From b1485f759fc94394183dcabc567a028ef8201067 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sat, 27 Jun 2026 12:02:20 -0400 Subject: [PATCH] fix(test_gui2_parity): poll for set_value/click to propagate instead of time.sleep The 'time.sleep + assert' pattern is a guaranteed race condition in batched runs (per workflow's documented anti-pattern). In the live_gui batched test suite, _process_pending_gui_tasks is competing for CPU with 16 xdist workers, so 1.5s is sometimes not enough for a single set_value or click to propagate through the gui task queue. Fix: replace time.sleep(1.5) with a 10s poll loop that waits for the expected state (per the same pattern used in test_gui2_custom_callback_hook_works which was already fixed in commit 09eaf69a for the same reason). This is a test-only fix; no production code changes. --- tests/test_gui2_parity.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/test_gui2_parity.py b/tests/test_gui2_parity.py index 9a0ecf94..483e4698 100644 --- a/tests/test_gui2_parity.py +++ b/tests/test_gui2_parity.py @@ -42,20 +42,30 @@ def test_gui2_set_value_hook_works(live_gui: Any) -> None: def test_gui2_click_hook_works(live_gui: Any) -> None: """ - - - Tests that the 'click' GUI hook for the 'Reset' button is implemented. + Tests that the 'click' GUI hook for the 'Reset' button is implemented. """ client = ApiHookClient() assert client.wait_for_server(timeout=10) # First, set some state that 'Reset' would clear. test_value = "This text should be cleared by the reset button." client.set_value('ai_input', test_value) - time.sleep(1.5) + # Poll for the set_value to propagate through the gui task queue + # (per workflow's race-condition anti-pattern guidance: time.sleep + assert + # is a guaranteed race in batched runs). + deadline = time.time() + 10.0 + while time.time() < deadline: + if client.get_value('ai_input') == test_value: + break + time.sleep(0.1) assert client.get_value('ai_input') == test_value # Now, trigger the click client.click('btn_reset') - time.sleep(1.5) + # Poll for the reset click to propagate (and verify the value clears). + deadline = time.time() + 10.0 + while time.time() < deadline: + if client.get_value('ai_input') == "": + break + time.sleep(0.1) # Verify it was reset assert client.get_value('ai_input') == "" def test_gui2_custom_callback_hook_works(live_gui: Any) -> None: