Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/module-release-test-gc.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Made the test that dead systems' variable modules are released during a test independent of automatic garbage-collection timing.
18 changes: 15 additions & 3 deletions policyengine_uk/tests/test_variable_module_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,21 @@ def test_dead_systems_modules_are_released_while_a_test_runs(request, monkeypatc
lambda **kwargs: scans.append(kwargs) or release(**kwargs),
)
owners = []
for _ in range(max_new + 3):
Simulation(situation=SITUATION).calculate("income_tax", 2026)
owners.append(len(conftest._variable_module_owners()))
# Module names carry id(system), an address. If a collection frees a dead
# system during the loop, a later system can reuse its address and
# overwrite its modules rather than add an owner, so no release falls due:
# with a collection after each build, owners stopped at live + 6 and no
# release ran. With automatic collection off, the dead systems wait for the
# release's own collection, so each build adds an owner.
collecting = gc.isenabled()
gc.disable()
try:
for _ in range(max_new + 3):
Simulation(situation=SITUATION).calculate("income_tax", 2026)
owners.append(len(conftest._variable_module_owners()))
finally:
if collecting:
gc.enable()
# Released as each new system starts adding its variables, so at most
# max_new dead systems' modules beyond the live ones, plus the newest
# system's. Without the release the last count would be live + 11.
Expand Down
Loading