From 4de75c3a9de9171d5634cebd5fd6a1b3325bbcda Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 12 Mar 2020 19:08:00 -0400 Subject: [PATCH] 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. --- tests/test_cancellation.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/test_cancellation.py b/tests/test_cancellation.py index e121baf..603fff0 100644 --- a/tests/test_cancellation.py +++ b/tests/test_cancellation.py @@ -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. """ @@ -132,10 +133,17 @@ def test_cancel_single_subactor(arb_addr): ) 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():