From ee8a66233f4853c091976005a2d0f8245b3eceea Mon Sep 17 00:00:00 2001 From: fangliquanflq Date: Mon, 24 Aug 2026 02:58:13 +0800 Subject: [PATCH] test(gateway): preserve replacement handles across close races --- tests/gateway/test_session_db_recovery.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/gateway/test_session_db_recovery.py b/tests/gateway/test_session_db_recovery.py index bee6e253a8..3043dd3c02 100644 --- a/tests/gateway/test_session_db_recovery.py +++ b/tests/gateway/test_session_db_recovery.py @@ -205,6 +205,7 @@ def test_close_all_rejects_and_closes_inflight_success() -> None: entered = threading.Event() release = threading.Event() handle = object() + replacement = object() closed: list[object] = [] result: list[object | None] = [] @@ -217,13 +218,14 @@ def test_close_all_rejects_and_closes_inflight_success() -> None: thread.start() assert entered.wait(timeout=5) cache.close_all(closed.append) + assert cache.get(path, lambda: replacement) is replacement release.set() thread.join(timeout=5) assert not thread.is_alive() assert result == [None] assert closed == [handle] - assert cache.status_for(path) == "unknown" + assert cache.get(path, lambda: object()) is replacement def test_close_all_preserves_inflight_failure() -> None: @@ -233,6 +235,7 @@ def test_close_all_preserves_inflight_failure() -> None: release = threading.Event() errors: list[BaseException] = [] failure = OSError("original open failure") + replacement = object() def opener(): entered.set() @@ -249,12 +252,13 @@ def test_close_all_preserves_inflight_failure() -> None: thread.start() assert entered.wait(timeout=5) cache.close_all(lambda handle: None) + assert cache.get(path, lambda: replacement) is replacement release.set() thread.join(timeout=5) assert not thread.is_alive() assert errors == [failure] - assert cache.status_for(path) == "unknown" + assert cache.get(path, lambda: object()) is replacement def test_recovered_db_rows_survive_fallback_structural_save(monkeypatch, tmp_path) -> None: