Add a "cancel arrives during a sync sleep in child" test
This appears to demonstrate the same bug found in #156. It looks like cancelling a subactor with a child, while that child is running sync code, can result in the child never getting cancelled due to some strange condition where the internal nurseries aren't being torn down as expected when a `trio.Cancelled` is raised.bug_in_debug
parent
acb4cb0b2b
commit
0e344eead8
|
@ -413,3 +413,34 @@ def test_cancel_via_SIGINT_other_task(
|
||||||
|
|
||||||
with pytest.raises(KeyboardInterrupt):
|
with pytest.raises(KeyboardInterrupt):
|
||||||
tractor.run(main)
|
tractor.run(main)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async def spin_for(period=3):
|
||||||
|
"Sync sleep."
|
||||||
|
time.sleep(period)
|
||||||
|
|
||||||
|
|
||||||
|
async def spawn():
|
||||||
|
async with tractor.open_nursery() as tn:
|
||||||
|
portal = await tn.run_in_actor('sleeper', spin_for)
|
||||||
|
|
||||||
|
|
||||||
|
def test_cancel_while_childs_child_in_sync_sleep(
|
||||||
|
loglevel,
|
||||||
|
start_method,
|
||||||
|
spawn_backend,
|
||||||
|
):
|
||||||
|
"""Verify that a child cancelled while executing sync code is torn
|
||||||
|
down even when that cancellation is triggered by the parent
|
||||||
|
2 nurseries "up".
|
||||||
|
"""
|
||||||
|
async def main():
|
||||||
|
with trio.fail_after(2):
|
||||||
|
async with tractor.open_nursery() as tn:
|
||||||
|
portal = await tn.run_in_actor('spawn', spawn)
|
||||||
|
await trio.sleep(1)
|
||||||
|
assert 0
|
||||||
|
|
||||||
|
with pytest.raises(AssertionError):
|
||||||
|
tractor.run(main)
|
||||||
|
|
Loading…
Reference in New Issue