Skip to content

Commit cd5c8a4

Browse files
committed
Harden flaky linked-grid test: assert session_key, not id()
test_show_linked_grid_one_state_manager_per_experiment compared id() of StateManagers it didn't retain, so GC could reuse an id within a run and make the id-based set flaky in full-session order (passed in isolation / the gate, but could report 1 distinct id instead of 2). Assert on the stable _session_key (demo__exp0 / demo__exp1) — the actual one-StateManager-per-experiment invariant. Verification harness only; no change to any reviewed unit.
1 parent 5b7a545 commit cd5c8a4

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

tests/test_view_grid.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,10 @@ def test_show_linked_grid_one_state_manager_per_experiment(mock_streamlit, cache
274274

275275
def _make_fc(sink):
276276
def fc(self, key=None, state_manager=None, height=None):
277-
sink.append(id(state_manager))
277+
# Record the StateManager's stable session_key (not id(): unretained
278+
# StateManagers can be GC'd and have their id() reused within a run,
279+
# making an id-based set flaky in the full-session test order).
280+
sink.append(state_manager._session_key)
278281
return None
279282

280283
return fc
@@ -284,7 +287,9 @@ def fc(self, key=None, state_manager=None, height=None):
284287
with ExitStack() as stack:
285288
_patch_component_calls(stack, _make_fc(seen))
286289
show_linked_grid(two_exp, builders, tool="demo", side_by_side=side_by_side)
287-
assert len(set(seen)) == 2, f"side_by_side={side_by_side}"
290+
# one StateManager per experiment -> two distinct session keys.
291+
assert len(set(seen)) == 2, f"side_by_side={side_by_side}: {seen}"
292+
assert set(seen) == {"demo__exp0", "demo__exp1"}, seen
288293

289294

290295
# --------------------------------------------------------------------------- #

0 commit comments

Comments
 (0)