From 8bd4db150b6708b4c66b89b2a6ed6f5e48a21a5d Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 13 Apr 2023 18:06:44 -0400 Subject: [PATCH] Adjust aio test for silent cancellation by parent --- tests/test_infected_asyncio.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/test_infected_asyncio.py b/tests/test_infected_asyncio.py index 775ee98..dd9d681 100644 --- a/tests/test_infected_asyncio.py +++ b/tests/test_infected_asyncio.py @@ -15,6 +15,7 @@ import tractor from tractor import ( to_asyncio, RemoteActorError, + ContextCancelled, ) from tractor.trionics import BroadcastReceiver @@ -224,14 +225,23 @@ def test_context_spawns_aio_task_that_errors( await trio.sleep_forever() - with pytest.raises(RemoteActorError) as excinfo: - trio.run(main) + return await ctx.result() - err = excinfo.value - assert isinstance(err, RemoteActorError) if parent_cancels: - assert err.type == trio.Cancelled + # bc the parent made the cancel request, + # the error is not raised locally but instead + # the context is exited silently + res = trio.run(main) + assert isinstance(res, ContextCancelled) + assert 'root' in res.canceller[0] + else: + expect = RemoteActorError + with pytest.raises(expect) as excinfo: + trio.run(main) + + err = excinfo.value + assert isinstance(err, expect) assert err.type == AssertionError