From a1d75625e46bf19452365ce5f4ec5be960130fbf Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 24 Feb 2025 13:08:23 -0500 Subject: [PATCH] Draft test-doc for "out-of-band" `asyncio.Task`.. Since there's no way to activate `greenback`'s portal in such cases, we should at least have a test verifying our very loud error about the inability to support this usage.. --- tests/conftest.py | 12 ++++++++++++ tests/devx/test_pause_from_non_trio.py | 25 +++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 5ce8442..810b642 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -150,6 +150,18 @@ def pytest_generate_tests(metafunc): metafunc.parametrize("start_method", [spawn_backend], scope='module') +# TODO: a way to let test scripts (like from `examples/`) +# guarantee they won't registry addr collide! +# @pytest.fixture +# def open_test_runtime( +# reg_addr: tuple, +# ) -> AsyncContextManager: +# return partial( +# tractor.open_nursery, +# registry_addrs=[reg_addr], +# ) + + def sig_prog(proc, sig): "Kill the actor-process with ``sig``." proc.send_signal(sig) diff --git a/tests/devx/test_pause_from_non_trio.py b/tests/devx/test_pause_from_non_trio.py index f3fd15a..3a7140e 100644 --- a/tests/devx/test_pause_from_non_trio.py +++ b/tests/devx/test_pause_from_non_trio.py @@ -218,10 +218,9 @@ def expect_any_of( ) return expected_patts - # yield child -def test_pause_from_asyncio_task( +def test_sync_pause_from_aio_task( spawn, ctlc: bool # ^TODO, fix for `asyncio`!! @@ -327,3 +326,25 @@ def test_pause_from_asyncio_task( child.sendline('c') child.expect(EOF) + + +def test_sync_pause_from_non_greenbacked_aio_task(): + ''' + Where the `breakpoint()` caller task is NOT spawned by + `tractor.to_asyncio` and thus never activates + a `greenback.ensure_portal()` beforehand, presumably bc the task + was started by some lib/dep as in often seen in the field. + + Ensure sync pausing works when the pause is in, + + - the root actor running in infected-mode? + |_ since we don't need any IPC to acquire the debug lock? + |_ is there some way to handle this like the non-main-thread case? + + All other cases need to error out appropriately right? + + - for any subactor we can't avoid needing the repl lock.. + |_ is there a way to hook into `asyncio.ensure_future(obj)`? + + ''' + pass