Skip to content

Commit

Permalink
Test cancel via api and keyboard interrupt
Browse files Browse the repository at this point in the history
An initial attempt to discover an issue with trio-run-inprocess.
This is a good test to have regardless.
  • Loading branch information
goodboy committed Jul 20, 2020
1 parent 3811426 commit 28799a3
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions tests/test_cancellation.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ def do_nothing():
pass


def test_cancel_single_subactor(arb_addr):
@pytest.mark.parametrize('mechanism', ['nursery_cancel', KeyboardInterrupt])
def test_cancel_single_subactor(arb_addr, mechanism):
"""Ensure a ``ActorNursery.start_actor()`` spawned subactor
cancels when the nursery is cancelled.
"""
Expand All @@ -132,10 +133,17 @@ async def spawn_actor():
)
assert (await portal.run(__name__, 'do_nothing')) is None

# would hang otherwise
await nursery.cancel()
if mechanism == 'nursery_cancel':
# would hang otherwise
await nursery.cancel()
else:
raise mechanism

tractor.run(spawn_actor, arbiter_addr=arb_addr)
if mechanism == 'nursery_cancel':
tractor.run(spawn_actor, arbiter_addr=arb_addr)
else:
with pytest.raises(mechanism):
tractor.run(spawn_actor, arbiter_addr=arb_addr)


async def stream_forever():
Expand Down

0 comments on commit 28799a3

Please sign in to comment.