MCPcopy
hub / github.com/tornadoweb/tornado / test_stop_in_callback

Method test_stop_in_callback

tornado/test/tcpserver_test.py:73–116  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

71
72 @gen_test
73 def test_stop_in_callback(self):
74 # Issue #2069: calling server.stop() in a loop callback should not
75 # raise EBADF when the loop handles other server connection
76 # requests in the same loop iteration
77
78 class TestServer(TCPServer):
79 @gen.coroutine
80 def handle_stream(self, stream, address):
81 server.stop() # type: ignore
82 yield stream.read_until_close()
83
84 sock, port = bind_unused_port()
85 server = TestServer()
86 server.add_socket(sock)
87 server_addr = ("localhost", port)
88 N = 40
89 clients = [IOStream(socket.socket()) for i in range(N)]
90 connected_clients = []
91
92 @gen.coroutine
93 def connect(c):
94 try:
95 yield c.connect(server_addr)
96 except OSError:
97 pass
98 else:
99 connected_clients.append(c)
100
101 yield [connect(c) for c in clients]
102
103 self.assertGreater(len(connected_clients), 0, "all clients failed connecting")
104 try:
105 if len(connected_clients) == N:
106 # Ideally we'd make the test deterministic, but we're testing
107 # for a race condition in combination with the system's TCP stack...
108 self.skipTest(
109 "at least one client should fail connecting "
110 "for the test to be meaningful"
111 )
112 finally:
113 for c in connected_clients:
114 c.close()
115
116 # Here tearDown() would re-raise the EBADF encountered in the IO loop
117
118
119@skipIfNonUnix

Callers

nothing calls this directly

Calls 5

bind_unused_portFunction · 0.90
IOStreamClass · 0.90
add_socketMethod · 0.80
TestServerClass · 0.70
closeMethod · 0.45

Tested by

no test coverage detected