Skip to content

test(bootstrap): isolate reset/0 tests from concurrent VM builds - #448

Merged
davydog187 merged 2 commits into
mainfrom
fix/bootstrap-test-isolation
Dec 1, 2026
Merged

davydog187 merged 2 commits into
mainfrom
fix/bootstrap-test-isolation

Conversation

@davydog187

Copy link
Copy Markdown
Contributor

Fixes a flake seen locally and on CI (PR 440, job "Build and test (1.19.0 / OTP 28.1)", run 46663403944, seed 973823): reset/0 left {Lua, :default_lua} behind after a concurrent cold start in Lua.VM.BootstrapTest, which passes alone and on rerun.

Cause

The memoized templates live in :persistent_term, which is node-global. Lua.VM.BootstrapTest was async: true, and its reset/0 tests assert that the keys are absent right after Bootstrap.reset(). Any other async test that calls Lua.new/1 in that window cold-starts and re-puts {Lua, :default_lua} (and :base_state), so the assertion sees the key. With several thousand tests across 8 cases (and more on a loaded machine) the window gets hit now and then.

Deterministic reproduction: a test that calls reset/0, runs Lua.new() in another process, then asserts the key is missing fails every time (probe kept outside the repo).

Test-only

reset/0 is documented as safe to call concurrently with fetch/2; concurrent callers just rebuild. No library change.

Changes

  • Move the reset/0 tests into Lua.VM.BootstrapResetTest with async: false; ExUnit runs it only after every async module finishes, so nothing can repopulate the keys mid-test.
  • Separate, found while verifying with two concurrent mix test runs: five tests wrote to fixed (or per-VM unique_integer) paths under System.tmp_dir!/0, so a second run's cleanup deleted the first run's files (File.Error in SuiteRunnerTest and Mix.Tasks.Lua.SuiteTest). Add the OS pid to those paths.

Verification

mix format --check-formatted, mix compile --warnings-as-errors, mix test: 2794 tests, 0 failures. 20 full runs with random seeds, 5 of them overlapping a second mix test in another worktree: all green. An earlier 20-run pass without the tmp-path change had 1 failure, in an overlapped run, from the tmp-path collision, never from the bootstrap test.

The reset/0 tests assert that the node-global :persistent_term keys are
absent right after a reset. Under async: true any other test calling
Lua.new/1 between the reset and the assertion re-memoizes the default
template, so the suite failed intermittently with "reset/0 left
{Lua, :default_lua} behind", most often when machine load widened the
window. Move them to their own async: false module, which ExUnit runs only
after every async module has finished.

Test-only: reset/0 is documented as safe against concurrent fetch/2.
Five tests wrote under fixed or per-VM-unique names in System.tmp_dir!/0.
Two mix test runs on one machine (parallel worktrees) shared those paths,
and one run's cleanup deleted the other's files mid-test, failing
SuiteRunnerTest and Mix.Tasks.Lua.SuiteTest with File.Error. Add the OS pid
to each path.
@davydog187
davydog187 merged commit c9012c9 into main Dec 1, 2026
5 checks passed
@davydog187
davydog187 deleted the fix/bootstrap-test-isolation branch December 1, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant