Skip to content

Commit

Permalink
Add a "cancel arrives during a sync sleep in child" test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
goodboy committed Oct 13, 2020
1 parent acb4cb0 commit 0e344ee
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/test_cancellation.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,34 @@ async def main():

with pytest.raises(KeyboardInterrupt):
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)

0 comments on commit 0e344ee

Please sign in to comment.