From 49ac90deca161e44d70346872d2e42405048fc46 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 12 Nov 2026 21:47:56 +0000 Subject: [PATCH] Deflake GPU-badge re-send test: settle the probe thread first QuantUIApp starts a background quantui-gpu-detect thread at construction that sets _status_html.value when it finishes. When that landed after the test had patched send_state, it recorded an extra "value" send and test_settings_tab_resends_the_badge failed (~1 in 3 when run alongside the viewer test files). Give TestB1GpuBadge its own app fixture that stubs gpu_offload.probe_gpu (instant, hardware-independent) and joins this app's detect thread before the test patches send_state. App behaviour is unchanged; the test still fails if the Settings tab stops re-sending. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017NANrpr6Ez2krGCpnwM4yW --- tests/test_uipolish.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/test_uipolish.py b/tests/test_uipolish.py index c6e72731..40acbcf4 100644 --- a/tests/test_uipolish.py +++ b/tests/test_uipolish.py @@ -86,6 +86,31 @@ def test_plotly_camera_looks_along_the_flattest_axis(self): class TestB1GpuBadge: + @pytest.fixture + def app(self, tmp_path, monkeypatch): + """An app whose background GPU probe has already updated the badge. + + Construction starts a ``quantui-gpu-detect`` thread that sets + ``_status_html.value`` when it finishes. If that lands after the test + patches ``send_state``, it records an extra send and the test flakes. + Stub the probe so it is instant and hardware-independent, then join + this app's detect thread before handing the app to the test. + """ + import threading + + from quantui import gpu_offload + + monkeypatch.setenv("QUANTUI_SETTINGS_PATH", str(tmp_path / "settings.json")) + monkeypatch.setattr(gpu_offload, "probe_gpu", lambda: (False, None, "stub")) + before = set(threading.enumerate()) + app = QuantUIApp() + # The stubbed probe may already be done (then it is not listed). + for t in threading.enumerate(): + if t.name == "quantui-gpu-detect" and t not in before: + t.join(timeout=30) + assert not t.is_alive(), "GPU probe thread did not finish" + return app + def test_settings_tab_resends_the_badge(self, app, monkeypatch): sent = [] monkeypatch.setattr(