From 18a850c186e23afa5d9ffdfcf3d4f536bb60ae77 Mon Sep 17 00:00:00 2001 From: Tim Stumbaugh Date: Wed, 12 Jan 2022 14:37:39 -0700 Subject: [PATCH] Use an event instead --- trio/tests/test_subprocess.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/trio/tests/test_subprocess.py b/trio/tests/test_subprocess.py index 2627521380..65abe13e50 100644 --- a/trio/tests/test_subprocess.py +++ b/trio/tests/test_subprocess.py @@ -11,6 +11,7 @@ from .. import ( ClosedResourceError, + Event, Process, _core, fail_after, @@ -573,21 +574,20 @@ async def test_for_leaking_fds(): # regression test for #2209 -@pytest.mark.skipif(not posix, reason="Regression test for Linux-only bug") async def test_subprocess_pidfd_unnotified(): noticed_exit = None async def wait_and_tell(proc) -> None: nonlocal noticed_exit - noticed_exit = False + noticed_exit = Event() await proc.wait() - noticed_exit = True + noticed_exit.set() proc = await open_process(SLEEP(9999)) async with _core.open_nursery() as nursery: nursery.start_soon(wait_and_tell, proc) await wait_all_tasks_blocked() - assert noticed_exit is False + assert isinstance(noticed_exit, Event) proc.terminate() # without giving trio a chance to do so, with assert_no_checkpoints(): @@ -595,5 +595,8 @@ async def wait_and_tell(proc) -> None: proc._proc.wait() # force a call to poll (that closes the pidfd on linux) proc.poll() - await wait_all_tasks_blocked() - assert noticed_exit, "child task wasn't woken after poll, DEADLOCK" + with move_on_after(5): + # Some platforms use threads to wait for exit, so it might take a bit + # for everything to notice + await noticed_exit.wait() + assert noticed_exit.is_set(), "child task wasn't woken after poll, DEADLOCK"