From 8d46d26abe002dc54a80c729285ba10e3e951d6e Mon Sep 17 00:00:00 2001 From: Will Miao Date: Sun, 30 Aug 2026 22:14:04 +0800 Subject: [PATCH] fix(tests): deflake recipe open stats tests by shrinking debounce in tests The four tests that wait on the background debounced write race against SAVE_DELAY (1.0s): _wait_for_save polls 100 x 0.01s = 1.0s, exactly equal to the debounce, leaving zero slack. On a loaded CI runner the write lands after the poll gives up, failing intermittently with 'Recipe open stats file was never written' (5 of 62 backend runs since the tests landed). Shrink SAVE_DELAY to 0.05s in _prepare so the write lands ~20x inside the poll window. The debounce duration is not what these tests verify; production default stays 1.0s. --- tests/utils/test_recipe_open_stats.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/utils/test_recipe_open_stats.py b/tests/utils/test_recipe_open_stats.py index 8f283638..cf30de48 100644 --- a/tests/utils/test_recipe_open_stats.py +++ b/tests/utils/test_recipe_open_stats.py @@ -24,6 +24,11 @@ def _prepare(tmp_path: Path, monkeypatch: pytest.MonkeyPatch): monkeypatch.setattr( stats_module, "get_settings_dir", lambda create=True: str(settings_dir) ) + # Shrink the debounce well below the 100 x 0.01s poll window in + # _wait_for_save so the background write always lands with a wide margin. + # The debounce duration is not what these tests verify; SAVE_DELAY stays + # at its production default (1.0s) outside this test module. + monkeypatch.setattr(RecipeOpenStats, "SAVE_DELAY", 0.05) created_tasks = [] real_create_task = stats_module.asyncio.create_task