-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move testing function to new testing directory
- Loading branch information
1 parent
aabfdcb
commit fb10a80
Showing
5 changed files
with
24 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import asyncio | ||
|
||
|
||
async def wait_for_pending_wakeups(max_yields=20, raise_if_exceeded=True): | ||
"""Allow any ready asyncio tasks to be woken up. | ||
Used in: | ||
- Tests to allow tasks like ``set()`` to start so that signal | ||
puts can be tested | ||
- `observe_value` to allow it to be wrapped in `asyncio.wait_for` | ||
with a timeout | ||
""" | ||
loop = asyncio.get_event_loop() | ||
# If anything has called loop.call_soon or is scheduled a wakeup | ||
# then let it run | ||
for _ in range(max_yields): | ||
await asyncio.sleep(0) | ||
if not loop._ready: # type: ignore # noqa: SLF001 | ||
return | ||
if raise_if_exceeded: | ||
raise RuntimeError(f"Tasks still scheduling wakeups after {max_yields} yields") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters