Skip to content

Commit

Permalink
Made test_start_task_soon_cancel_immediately() less flaky
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Oct 12, 2024
1 parent 65ef48a commit 012a60c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/test_from_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,17 +419,21 @@ def test_start_task_soon_cancel_immediately(
self, anyio_backend_name: str, anyio_backend_options: dict[str, Any]
) -> None:
cancelled = False
done_event = threading.Event()

async def event_waiter() -> None:
nonlocal cancelled
try:
await sleep(3)
except get_cancelled_exc_class():
cancelled = True
finally:
done_event.set()

with start_blocking_portal(anyio_backend_name, anyio_backend_options) as portal:
future = portal.start_task_soon(event_waiter)
future.cancel()
done_event.wait(10)

assert cancelled

Expand Down

0 comments on commit 012a60c

Please sign in to comment.