From c38d0f826e045db66f6be5cf536973157be763c2 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 14 Dec 2021 10:54:35 -0500 Subject: [PATCH] Add an unserializable value causes error before started test --- tests/test_context_stream_semantics.py | 29 +++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/test_context_stream_semantics.py b/tests/test_context_stream_semantics.py index 4c74a9a..b86c21f 100644 --- a/tests/test_context_stream_semantics.py +++ b/tests/test_context_stream_semantics.py @@ -58,6 +58,33 @@ from conftest import tractor_test _state: bool = False +@tractor.context +async def error_before_started( + ctx: tractor.Context, +) -> None: + # send an unserializable type + await ctx.started(object()) + + +def test_error_before_started(): + async def main(): + async with tractor.open_nursery() as n: + portal = await n.start_actor( + 'errorer', + enable_modules=[__name__], + ) + + async with portal.open_context( + error_before_started + ) as (ctx, sent): + await trio.sleep(1) + + with pytest.raises(tractor.RemoteActorError) as excinfo: + trio.run(main) + + assert excinfo.value.type == TypeError + + @tractor.context async def too_many_starteds( ctx: tractor.Context, @@ -466,7 +493,7 @@ async def cancel_self( try: async with ctx.open_stream(): pass - except ContextCancelled: + except tractor.ContextCancelled: pass # check a real ``trio.Cancelled`` is raised on a checkpoint