"""Tearing a node down must not swallow a cancellation meant for the caller.""" import asyncio import pytest from fluksio.flow.nodes import DelayNode def test_stop_cron_lets_the_callers_cancellation_through(): async def stubborn() -> None: """A loop whose shutdown does not answer the first cancellation.""" try: await asyncio.sleep(3600) except asyncio.CancelledError: await asyncio.sleep(3600) async def scenario() -> None: node = DelayNode(params={"cron": "* * * * *"}) node._stop_cron = asyncio.Event() node._cron_task = asyncio.create_task(stubborn()) stopping = asyncio.create_task(node.stop_cron()) await asyncio.sleep(0.05) # let it reach the await on the cron task stopping.cancel() with pytest.raises(asyncio.CancelledError): await stopping node._cron_task.cancel() asyncio.run(scenario())