MCPcopy Index your code
hub / github.com/python/cpython / _test_recv

Method _test_recv

Lib/test/_test_eintr.py:210–243  ·  view source on GitHub ↗
(self, recv_func)

Source from the content-addressed store, hash-verified

208
209 @unittest.skipUnless(hasattr(socket, 'socketpair'), 'needs socketpair()')
210 def _test_recv(self, recv_func):
211 rd, wr = socket.socketpair()
212 self.addCleanup(rd.close)
213 # wr closed explicitly by parent
214
215 # single-byte payload guard us against partial recv
216 data = [b"x", b"y", b"z"]
217
218 code = '\n'.join((
219 'import os, socket, sys, time',
220 '',
221 'fd = int(sys.argv[1])',
222 f'family = {int(wr.family)}',
223 f'sock_type = {int(wr.type)}',
224 f'data = {data!r}',
225 f'sleep_time = {self.sleep_time!r}',
226 '',
227 'wr = socket.fromfd(fd, family, sock_type)',
228 'os.close(fd)',
229 '',
230 'with wr:',
231 ' for item in data:',
232 ' # let the parent block on recv()',
233 ' time.sleep(sleep_time)',
234 ' wr.sendall(item)',
235 ))
236
237 fd = wr.fileno()
238 proc = self.subprocess(code, str(fd), pass_fds=[fd])
239 with kill_on_error(proc):
240 wr.close()
241 for item in data:
242 self.assertEqual(item, recv_func(rd, len(item)))
243 self.assertEqual(proc.wait(), 0)
244
245 def test_recv(self):
246 self._test_recv(socket.socket.recv)

Callers 2

test_recvMethod · 0.95
test_recvmsgMethod · 0.95

Calls 10

strFunction · 0.85
addCleanupMethod · 0.80
subprocessMethod · 0.80
kill_on_errorFunction · 0.70
socketpairMethod · 0.45
joinMethod · 0.45
filenoMethod · 0.45
closeMethod · 0.45
assertEqualMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected