The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(browser): the PR's polling waits use wait_until instead of sleep loops
Teknium98765280ea37
diff --git a/tests/tools/test_browser_launcher.py b/tests/tools/test_browser_launcher.pyindex 7f468533540..4ddaf0cb86b 100644--- a/tests/tools/test_browser_launcher.py+++ b/tests/tools/test_browser_launcher.py@@ -16,7 +16,6 @@ import subprocessimport sysimport textwrapimport threading-import timefrom pathlib import Pathimport pytest@@ -157,9 +156,8 @@ def test_a_bare_consumer_exiting_normally_stops_its_browser(fake_chromium):cwd=Path(__file__).resolve().parents[2],env=dict(os.environ), capture_output=True, text=True, timeout=120)pid = int(done.stdout.strip().splitlines()[0])- deadline = time.monotonic() + 10- while launcher._pid_alive(pid) and time.monotonic() < deadline:- time.sleep(0.1)+ with contextlib.suppress(AssertionError): # a survivor is killed, then reported with its stderr below+ _gone(pid, timeout=10)survived = launcher._pid_alive(pid)if survived and str(fake_chromium) in Path(f"/proc/{pid}/cmdline").read_text(errors="replace"):os.kill(pid, signal.SIGKILL)diff --git a/tests/tools/test_browser_orphan_reaper.py b/tests/tools/test_browser_orphan_reaper.pyindex 71a433b16ff..df7ad55993e 100644--- a/tests/tools/test_browser_orphan_reaper.py+++ b/tests/tools/test_browser_orphan_reaper.py@@ -7,13 +7,13 @@ import jsonimport osimport subprocessimport sys-import timefrom pathlib import Pathfrom types import SimpleNamespacefrom unittest.mock import patchimport pytest+from tests.waiting import wait_untilfrom tools import browser_launcher as launcherfrom tools.browser_launcher_holders import ns_identityfrom tools import browser_session as bs@@ -288,10 +288,8 @@ class TestPrivatePerProfileRecords:(outside / "Default").mkdir(parents=True)proc = subprocess.Popen([sys.executable, "-c", "import time; time.sleep(60)", f"--user-data-dir={outside}"])try:- deadline = time.monotonic() + 10- while launcher._start_time(proc.pid) is None and time.monotonic() < deadline:- time.sleep(0.05)- _record(records, pid=proc.pid, udd=str(outside), start_time=launcher._start_time(proc.pid))+ start_time = wait_until(lambda: launcher._start_time(proc.pid), what="the stand-in's start time")+ _record(records, pid=proc.pid, udd=str(outside), start_time=start_time)assert launcher.reap_orphaned_browsers() == 0assert records.terminated == []diff --git a/tests/tools/test_browser_pm.py b/tests/tools/test_browser_pm.pyindex 9b655e6eb94..5ab264a3c66 100644--- a/tests/tools/test_browser_pm.py+++ b/tests/tools/test_browser_pm.py@@ -4,13 +4,13 @@ Chromium (or the user's explicit override), acquired through PM at most once perimport jsonimport osimport sys-import timefrom pathlib import Pathimport pytestimport pmfrom pm import paths+from tests.waiting import wait_untilfrom tools import browser_launcher as launcher@@ -225,9 +225,7 @@ def test_exact_pm_child_receives_composed_scrubbed_environment(browser_store, motry:assert err is Nonechild_file = Path(browser.user_data_dir, "child.json")- deadline = time.monotonic() + 5- while not child_file.exists() and time.monotonic() < deadline:- time.sleep(0.05)+ wait_until(child_file.exists, what="the fake Chromium to write child.json")child = json.loads(child_file.read_text())finally:launcher.stop_browser("pm-child")diff --git a/tests/tools/test_sandbox_port_forward.py b/tests/tools/test_sandbox_port_forward.pyindex d80dd3f4dde..37b356daefb 100644--- a/tests/tools/test_sandbox_port_forward.py+++ b/tests/tools/test_sandbox_port_forward.py@@ -5,7 +5,6 @@ import socketimport subprocessimport sysimport threading-import timeimport pytest@@ -68,9 +67,7 @@ def test_only_a_connection_that_never_reaches_its_target_counts_as_a_forward_failocal_relay.append((env, dead))assert _relay(streams.forward_port(env, dead)) == b""- deadline = time.monotonic() + 10- while streams.forward_failures(env, dead) == 0 and time.monotonic() < deadline:- time.sleep(0.05)+ wait_until(lambda: streams.forward_failures(env, dead), what="the dead port's forward failure")assert streams.forward_failures(env, dead) == 1assert streams.forward_failures(env, live) == 0