Skip to content

Commit 8eaf3ac

Browse files
authored
improve flaky asyncio test (#639)
1 parent bdc99ae commit 8eaf3ac

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

test/test_server_asyncio.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,17 @@ def connection_made(self, transport):
223223

224224
protocol.transport.close() # close isn't synchronous and there's no notification that it's done
225225
# so we have to wait a bit
226-
yield from asyncio.sleep(0.1)
227-
self.assertTrue(len(server.active_connections) == 0)
226+
allowed_delay = 1
227+
deadline = time.monotonic() + allowed_delay
228+
while time.monotonic() <= deadline:
229+
yield from asyncio.sleep(0.1)
230+
if len(server.active_connections) == 0:
231+
break
232+
else:
233+
self.assertTrue(
234+
len(server.active_connections) == 0,
235+
msg="connections not closed within {} seconds".format(allowed_delay),
236+
)
228237

229238
server.server_close()
230239

0 commit comments

Comments
 (0)