Skip to content

Commit 012a60c

Browse files
committed
Made test_start_task_soon_cancel_immediately() less flaky
1 parent 65ef48a commit 012a60c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

tests/test_from_thread.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,17 +419,21 @@ def test_start_task_soon_cancel_immediately(
419419
self, anyio_backend_name: str, anyio_backend_options: dict[str, Any]
420420
) -> None:
421421
cancelled = False
422+
done_event = threading.Event()
422423

423424
async def event_waiter() -> None:
424425
nonlocal cancelled
425426
try:
426427
await sleep(3)
427428
except get_cancelled_exc_class():
428429
cancelled = True
430+
finally:
431+
done_event.set()
429432

430433
with start_blocking_portal(anyio_backend_name, anyio_backend_options) as portal:
431434
future = portal.start_task_soon(event_waiter)
432435
future.cancel()
436+
done_event.wait(10)
433437

434438
assert cancelled
435439

0 commit comments

Comments
 (0)