Clean up cancelled SSE wait tasks
This commit is contained in:
parent
ca3d34053f
commit
3f33994cdc
2 changed files with 50 additions and 14 deletions
|
|
@ -575,6 +575,39 @@ def test_render_stream_stops_when_shutdown_is_requested() -> None:
|
|||
asyncio.run(run())
|
||||
|
||||
|
||||
def test_render_stream_cleans_up_child_tasks_when_cancelled() -> None:
|
||||
async def run() -> None:
|
||||
queue = RefreshBroker().subscribe()
|
||||
shutdown_event = asyncio.Event()
|
||||
|
||||
async def render() -> str:
|
||||
return '<main id="morph">queue</main>'
|
||||
|
||||
stream = render_stream(
|
||||
queue,
|
||||
render,
|
||||
render_on_connect=False,
|
||||
shutdown_event=shutdown_event,
|
||||
)
|
||||
next_event = asyncio.create_task(anext(stream))
|
||||
await asyncio.sleep(0)
|
||||
next_event.cancel()
|
||||
|
||||
with pytest.raises(asyncio.CancelledError):
|
||||
await next_event
|
||||
|
||||
await asyncio.sleep(0)
|
||||
|
||||
pending = tuple(
|
||||
task
|
||||
for task in asyncio.all_tasks()
|
||||
if task is not asyncio.current_task() and not task.done()
|
||||
)
|
||||
assert pending == ()
|
||||
|
||||
asyncio.run(run())
|
||||
|
||||
|
||||
def test_render_dashboard_shows_dashboard_information_architecture(
|
||||
monkeypatch, tmp_path: Path
|
||||
) -> None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue