summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlton Gibson <carlton.gibson@noumenal.es>2024-05-28 19:36:34 +0200
committerNatalia <124304+nessita@users.noreply.github.com>2024-06-25 11:06:27 -0300
commitdd3d0483ab6953b769077f16828ff88d0c2bffc4 (patch)
tree583aae54fc05895dd1f364def36b3e95c57bbfca
parent3a4a44978a09472224f17330ed856c2226b14324 (diff)
[5.0.x] Refs #35059 -- Used asyncio.Event in ASGITest.test_asyncio_cancel_error to enforce specific interleaving.
Sleep call leads to a hard to trace error in CI. Using an Event is more deterministic, and should be less prone to environment variations. Bug in 11393ab1316f973c5fbb534305750740d909b4e4. Backport of f4a08b6ddfcacadfe9ff8364bf1c6c54f5dd370f from main.
-rw-r--r--tests/asgi/tests.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/tests/asgi/tests.py b/tests/asgi/tests.py
index bbb274d9ed..204f6d7bb2 100644
--- a/tests/asgi/tests.py
+++ b/tests/asgi/tests.py
@@ -477,6 +477,7 @@ class ASGITest(SimpleTestCase):
sync_waiter.active_threads.clear()
async def test_asyncio_cancel_error(self):
+ view_started = asyncio.Event()
# Flag to check if the view was cancelled.
view_did_cancel = False
# Track request_finished signal.
@@ -486,9 +487,10 @@ class ASGITest(SimpleTestCase):
# A view that will listen for the cancelled error.
async def view(request):
- nonlocal view_did_cancel
+ nonlocal view_started, view_did_cancel
+ view_started.set()
try:
- await asyncio.sleep(0.2)
+ await asyncio.sleep(0.1)
return HttpResponse("Hello World!")
except asyncio.CancelledError:
# Set the flag.
@@ -524,6 +526,7 @@ class ASGITest(SimpleTestCase):
self.assertNotEqual(handler_call["thread"], threading.current_thread())
# The signal sender is the handler class.
self.assertEqual(handler_call["kwargs"], {"sender": TestASGIHandler})
+ view_started.clear()
# Request cycle with a disconnect before the view can respond.
application = TestASGIHandler()
@@ -531,7 +534,7 @@ class ASGITest(SimpleTestCase):
communicator = ApplicationCommunicator(application, scope)
await communicator.send_input({"type": "http.request"})
# Let the view actually start.
- await asyncio.sleep(0.1)
+ await view_started.wait()
# Disconnect the client.
await communicator.send_input({"type": "http.disconnect"})
# The handler should not send a response.