forked from goodboy/tractor
1
0
Fork 0

Test cancel via api and keyboard interrupt

An initial attempt to discover an issue with trio-run-inprocess.
This is a good test to have regardless.
drop_cloudpickle
Tyler Goodlet 2020-03-12 19:08:00 -04:00
parent 5adf2f3b0c
commit 4de75c3a9d
1 changed files with 12 additions and 4 deletions

View File

@ -118,7 +118,8 @@ def do_nothing():
pass 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 """Ensure a ``ActorNursery.start_actor()`` spawned subactor
cancels when the nursery is cancelled. cancels when the nursery is cancelled.
""" """
@ -132,10 +133,17 @@ def test_cancel_single_subactor(arb_addr):
) )
assert (await portal.run(__name__, 'do_nothing')) is None assert (await portal.run(__name__, 'do_nothing')) is None
# would hang otherwise if mechanism == 'nursery_cancel':
await 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(): async def stream_forever():