Skip to content

Commit b5ba9d1

Browse files
committed
[aiohttp] Fix race condition in testing
The current code only yield once the thread have started, though there's a little chance that one of the thread did not had time to actually sent its request yet. That means that the requests will never be served and the thread will fail. This patch fixes this by making sure to do pass the execution to the asyncio loop between each join, just in case a request needs to be handled. Fixes #876
1 parent 549899e commit b5ba9d1

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

tests/contrib/aiohttp/test_request_safety.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,13 @@ def make_requests():
6868
ctx = self.tracer.get_call_context()
6969
threads = [threading.Thread(target=make_requests) for _ in range(10)]
7070
for t in threads:
71-
t.daemon = True
7271
t.start()
7372

74-
# we should yield so that this loop can handle
75-
# threads' requests
76-
yield from asyncio.sleep(0.5)
7773
for t in threads:
78-
t.join(timeout=0.5)
74+
# we should yield so that this loop can handle
75+
# threads' requests
76+
yield from asyncio.sleep(0.1)
77+
t.join(0.1)
7978

8079
# the trace is wrong but the Context is finished
8180
traces = self.tracer.writer.pop_traces()

0 commit comments

Comments
 (0)