From 7fddb4416b7372e7e9feb6d751694ae1592e7f50 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 27 Jan 2023 17:02:36 -0500 Subject: [PATCH] Handle `mp` spawn method cases in test suite --- .../advanced_faults/ipc_failure_during_stream.py | 7 ++++++- tests/conftest.py | 2 +- tests/test_advanced_faults.py | 12 +++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/examples/advanced_faults/ipc_failure_during_stream.py b/examples/advanced_faults/ipc_failure_during_stream.py index 8969222..6ce06b8 100644 --- a/examples/advanced_faults/ipc_failure_during_stream.py +++ b/examples/advanced_faults/ipc_failure_during_stream.py @@ -64,14 +64,17 @@ async def recv_and_spawn_net_killers( if i > 80: n.start_soon(break_channel_silently_then_error, stream) n.start_soon(close_stream_and_error, stream) + await trio.sleep_forever() async def main( - debug_mode: bool = True, + debug_mode: bool = False, + start_method: str = 'trio', ) -> None: async with open_nursery( + start_method=start_method, # NOTE: even debugger is used we shouldn't get # a hang since it never engages due to broken IPC @@ -88,6 +91,8 @@ async def main( ) as (ctx, sent): async with ctx.open_stream() as stream: for i in range(100): + + # this may break in the mp_spawn case await stream.send(i) with trio.move_on_after(2) as cs: diff --git a/tests/conftest.py b/tests/conftest.py index 9966022..3363cf5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -159,7 +159,7 @@ def loglevel(request): @pytest.fixture(scope='session') -def spawn_backend(request): +def spawn_backend(request) -> str: return request.config.option.spawn_backend diff --git a/tests/test_advanced_faults.py b/tests/test_advanced_faults.py index 8e747f9..8294f2a 100644 --- a/tests/test_advanced_faults.py +++ b/tests/test_advanced_faults.py @@ -19,6 +19,7 @@ from conftest import ( ) def test_child_breaks_ipc_channel_during_stream( debug_mode: bool, + spawn_backend: str, ): ''' Ensure we can (purposely) break IPC during streaming and it's still @@ -26,13 +27,22 @@ def test_child_breaks_ipc_channel_during_stream( SIGINT. ''' + expect_final_exc = KeyboardInterrupt + + if spawn_backend != 'trio': + if debug_mode: + pytest.skip('`debug_mode` only supported on `trio` spawner') + + expect_final_exc = trio.ClosedResourceError + mod = import_path( examples_dir() / 'advanced_faults' / 'ipc_failure_during_stream.py', root=examples_dir(), ) - with pytest.raises(KeyboardInterrupt): + with pytest.raises(expect_final_exc): trio.run( mod.main, debug_mode, + spawn_backend, )