From 4f8586a928059619f109b21c246e3c4e77dbbd52 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 27 Jan 2023 16:40:28 -0500 Subject: [PATCH] Wrap ex in new test, change dir helpers to use `pathlib.Path` --- ...ursery.py => ipc_failure_during_stream.py} | 0 tests/conftest.py | 24 ++++++++---- tests/test_advanced_faults.py | 38 +++++++++++++++++++ 3 files changed, 54 insertions(+), 8 deletions(-) rename examples/advanced_faults/{open_ctx_w_nursery.py => ipc_failure_during_stream.py} (100%) create mode 100644 tests/test_advanced_faults.py diff --git a/examples/advanced_faults/open_ctx_w_nursery.py b/examples/advanced_faults/ipc_failure_during_stream.py similarity index 100% rename from examples/advanced_faults/open_ctx_w_nursery.py rename to examples/advanced_faults/ipc_failure_during_stream.py diff --git a/tests/conftest.py b/tests/conftest.py index af42b85..9966022 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -7,6 +7,7 @@ import os import random import signal import platform +import pathlib import time import inspect from functools import partial, wraps @@ -113,14 +114,21 @@ no_windows = pytest.mark.skipif( ) -def repodir(): - """Return the abspath to the repo directory. - """ - dirname = os.path.dirname - dirpath = os.path.abspath( - dirname(dirname(os.path.realpath(__file__))) - ) - return dirpath +def repodir() -> pathlib.Path: + ''' + Return the abspath to the repo directory. + + ''' + # 2 parents up to step up through tests/ + return pathlib.Path(__file__).parent.parent.absolute() + + +def examples_dir() -> pathlib.Path: + ''' + Return the abspath to the examples directory as `pathlib.Path`. + + ''' + return repodir() / 'examples' def pytest_addoption(parser): diff --git a/tests/test_advanced_faults.py b/tests/test_advanced_faults.py new file mode 100644 index 0000000..8e747f9 --- /dev/null +++ b/tests/test_advanced_faults.py @@ -0,0 +1,38 @@ +''' +Sketchy network blackoutz, ugly byzantine gens, puedes eschuchar la +cancelacion?.. + +''' +import pytest +from _pytest.pathlib import import_path +import trio + +from conftest import ( + examples_dir, +) + + +@pytest.mark.parametrize( + 'debug_mode', + [False, True], + ids=['debug_mode', 'no_debug_mode'], +) +def test_child_breaks_ipc_channel_during_stream( + debug_mode: bool, +): + ''' + Ensure we can (purposely) break IPC during streaming and it's still + possible for the (simulated) user to kill the actor tree using + SIGINT. + + ''' + mod = import_path( + examples_dir() / 'advanced_faults' / 'ipc_failure_during_stream.py', + root=examples_dir(), + ) + + with pytest.raises(KeyboardInterrupt): + trio.run( + mod.main, + debug_mode, + )