Skip to content

Commit

Permalink
Add code to cancel and cleanup tasks after each run.
Browse files Browse the repository at this point in the history
Currently disabled since it can hide other problems present.
  • Loading branch information
kristjanvalur committed Apr 20, 2023
1 parent b7255b3 commit edf69d3
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/websockets/test_graphql_transport_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ async def ws_raw(http_client: HttpClient) -> AsyncGenerator[WebSocketClient, Non
await ws.close()
assert ws.closed

# loop cleanup code, similar to code from asyncio.run()
# disabled, can be enabled for debugging
return

loop = asyncio.get_running_loop()
current = asyncio.current_task(loop=loop)
to_cancel = [t for t in asyncio.all_tasks(loop=loop) if t is not current]
for task in to_cancel:
task.cancel()
await asyncio.gather(*to_cancel, return_exceptions=True)
for task in to_cancel:
if task.cancelled():
continue
if task.exception() is not None:
loop.call_exception_handler(
{
"message": "unhandled exception during test fixture cleanup",
"exception": task.exception(),
"task": task,
}
)


@pytest_asyncio.fixture
async def ws(ws_raw: WebSocketClient) -> WebSocketClient:
Expand Down

0 comments on commit edf69d3

Please sign in to comment.