Skip to content

Commit ac900f1

Browse files
test(sync-health): test_1595 no longer leaves the seam's modules on a dead database (#3254)
With dev's S1 (#4015) merged in, test_3254_skills_alerts.py's person-ending case fails when test_1595_sync_health_signals.py runs before it: the ack is refused as `expired`. It passes alone and on dev. Cause: test_1595's tmp_db evicts `database` and the db.* modules, and its _restore_sys_modules puts back only the names it lists. On this branch the poller's alerts go through platform_alerts, so a test here is the first to import services.ask_service and services.operator_queue_service, and both bind the transient `database`. Left loaded, the later file's clock fixture pins the live database's module globals and misses the copy ask_service still writes through, so the respond predicate reads the real clock against a row stamped with the pinned one. Both names join _STUBBED_MODULE_NAMES, so a test that first imported them pops them again. The pop now also drops the package attribute (module_split_guard.unbind), or `from services import ask_service` would keep handing out the popped copy (#3390). After the file, the set of modules bound to a stale `db` is the same as on dev. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HWna79vVmnezQdhpaGRKbw
1 parent 407c796 commit ac900f1

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎tests/unit/test_1595_sync_health_signals.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,26 @@
5454
"database",
5555
"services.sync_health_service",
5656
"services.agent_client",
57+
# #3254: the poller's alerts go through the platform-alert seam, so a test
58+
# here can be the first to import these two, and they bind the `database`
59+
# this file's tmp_db re-imports. Left loaded, a later file's clock pins
60+
# miss them (an ack read as `expired` in test_3254_skills_alerts.py).
61+
"services.ask_service",
62+
"services.operator_queue_service",
5763
]
5864

5965

6066
@pytest.fixture(autouse=True)
6167
def _restore_sys_modules():
68+
from module_split_guard import unbind
6269
saved = {name: sys.modules.get(name) for name in _STUBBED_MODULE_NAMES}
6370
try:
6471
yield
6572
finally:
6673
for name, value in saved.items():
6774
if value is None:
6875
sys.modules.pop(name, None)
76+
unbind(name) # else `from services import X` keeps the popped copy (#3390)
6977
else:
7078
sys.modules[name] = value
7179

0 commit comments

Comments
 (0)