Handle `mp` spawn method cases in test suite

ipc_failure_while_streaming
Tyler Goodlet 2023-01-27 17:02:36 -05:00
parent 1d92f2552a
commit 7fddb4416b
3 changed files with 18 additions and 3 deletions

View File

@ -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:

View File

@ -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

View File

@ -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,
)