MCPcopy
hub / github.com/urllib3/urllib3 / test_wait_for_socket

Function test_wait_for_socket

test/test_wait.py:39–79  ·  view source on GitHub ↗
(wfs: TYPE_WAIT_FOR, spair: TYPE_SOCKET_PAIR)

Source from the content-addressed store, hash-verified

37
38@pytest.mark.parametrize("wfs", variants)
39def test_wait_for_socket(wfs: TYPE_WAIT_FOR, spair: TYPE_SOCKET_PAIR) -> None:
40 a, b = spair
41
42 with pytest.raises(RuntimeError):
43 wfs(a, read=False, write=False)
44
45 assert not wfs(a, read=True, timeout=0)
46 assert wfs(a, write=True, timeout=0)
47
48 b.send(b"x")
49 assert wfs(a, read=True, timeout=0)
50 assert wfs(a, read=True, timeout=10)
51 assert wfs(a, read=True, timeout=None)
52
53 # Fill up the socket with data
54 a.setblocking(False)
55 try:
56 while True:
57 a.send(b"x" * 999999)
58 except OSError:
59 pass
60
61 # Now it's not writable anymore
62 assert not wfs(a, write=True, timeout=0)
63
64 # But if we ask for read-or-write, that succeeds
65 assert wfs(a, read=True, write=True, timeout=0)
66
67 # Unless we read from it
68 assert a.recv(1) == b"x"
69 assert not wfs(a, read=True, write=True, timeout=0)
70
71 # But if the remote peer closes the socket, then it becomes readable
72 b.close()
73 assert wfs(a, read=True, timeout=0)
74
75 # Waiting for a socket that's actually been closed is just a bug, and
76 # raises some kind of helpful exception (exact details depend on the
77 # platform).
78 with pytest.raises(Exception):
79 wfs(b, read=True)
80
81
82def test_wait_for_read_write(spair: TYPE_SOCKET_PAIR) -> None:

Callers

nothing calls this directly

Calls 3

sendMethod · 0.45
recvMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected