MCPcopy Index your code
hub / github.com/RustPython/RustPython / testSendAndRecvFds

Method testSendAndRecvFds

Lib/test/test_socket.py:7373–7408  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

7371@requireAttrs(socket, "AF_UNIX")
7372class SendRecvFdsTests(unittest.TestCase):
7373 def testSendAndRecvFds(self):
7374 def close_pipes(pipes):
7375 for fd1, fd2 in pipes:
7376 os.close(fd1)
7377 os.close(fd2)
7378
7379 def close_fds(fds):
7380 for fd in fds:
7381 os.close(fd)
7382
7383 # send 10 file descriptors
7384 pipes = [os.pipe() for _ in range(10)]
7385 self.addCleanup(close_pipes, pipes)
7386 fds = [rfd for rfd, wfd in pipes]
7387
7388 # use a UNIX socket pair to exchange file descriptors locally
7389 sock1, sock2 = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
7390 with sock1, sock2:
7391 socket.send_fds(sock1, [MSG], fds)
7392 # request more data and file descriptors than expected
7393 msg, fds2, flags, addr = socket.recv_fds(sock2, len(MSG) * 2, len(fds) * 2)
7394 self.addCleanup(close_fds, fds2)
7395
7396 self.assertEqual(msg, MSG)
7397 self.assertEqual(len(fds2), len(fds))
7398 self.assertEqual(flags, 0)
7399 # don't test addr
7400
7401 # test that file descriptors are connected
7402 for index, fds in enumerate(pipes):
7403 rfd, wfd = fds
7404 os.write(wfd, str(index).encode())
7405
7406 for index, rfd in enumerate(fds2):
7407 data = os.read(rfd, 100)
7408 self.assertEqual(data, str(index).encode())
7409
7410
7411class FreeThreadingTests(unittest.TestCase):

Callers

nothing calls this directly

Calls 10

lenFunction · 0.85
enumerateFunction · 0.85
strFunction · 0.85
addCleanupMethod · 0.80
pipeMethod · 0.45
socketpairMethod · 0.45
assertEqualMethod · 0.45
writeMethod · 0.45
encodeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected