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.
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user