Adjust core test to avoid lingering task (#88918)

This commit is contained in:
epenet 2023-02-28 18:03:36 +01:00 committed by GitHub
parent 36e6a879ad
commit ee144d34a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2034,7 +2034,8 @@ async def test_shutdown_does_not_block_on_shielded_tasks(
) -> None:
"""Ensure shutdown does not block on shielded tasks."""
result = asyncio.Future()
shielded_task = asyncio.shield(asyncio.sleep(10))
sleep_task = asyncio.ensure_future(asyncio.sleep(10))
shielded_task = asyncio.shield(sleep_task)
async def test_task():
try:
@ -2050,3 +2051,6 @@ async def test_shutdown_does_not_block_on_shielded_tasks(
assert result.done()
assert task.done()
assert time.monotonic() - start < 0.5
# Cleanup lingering task after test is done
sleep_task.cancel()