Skip to content

Give the test suite a temp dir of its own so concurrent runs stop sharing simulator claims - #176

Merged
bitomule merged 1 commit into
mainfrom
fix/test-suite-private-tmpdir
Dec 3, 2026
Merged

bitomule merged 1 commit into
mainfrom
fix/test-suite-private-tmpdir

Conversation

@bitomule

@bitomule bitomule commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Problem

Tests in internal/mav failed now and then on a Mac where other go test runs were going at the same time, while CI on the same commit was green. Each one passed alone:

  • TestStatusBarStepDoesNotOverwriteTheEvidenceTimestamp, TestScreenshotControlFlowActionsReachSimctl and seven TestOpen… / TestLaunch… tests failed in 0.00 s with «command failed».
  • TestFlowOverExistingRunHoldsTheClaimThroughItsSteps and TestNoRelaunchOpenKeepsTheSessionClaimAlive failed after 4–7 s with «the session must hold CLAIM-NORELAUNCH-001 …».
  • In the same conditions, TestFlowOpenIgnoresStaleCurrentRun, TestFlowRunContinuesExistingRunID and TestFlowRunDoesNotStealLiveManualRunPointer also failed with «command failed».

Cause

Simulator locks live under os.TempDir()/mav/sim-locks on purpose: a real claim (#171) must be visible to every mav process of the user. For the test suite, that folder is state shared with every other test run on the machine. The fixtures reuse fixed UDIDs:

  • "SIM" is the simulator in 46 test configs, including all of the 0.00 s failures above.
  • claimTestUDID builds CLAIM-<label>- + filepath.Base(t.TempDir()). That base is 001 in every process, so two suites both use CLAIM-NORELAUNCH-001.

When two suites run at once (two worktrees' make check), one refuses with sim_locked because the other's live run holds SIM. Or one suite's release removes or rewrites the lock the other has just taken. The #171 claim code behaves as designed. The problem is that the tests were not isolated.

Fix

TestMain now runs the suite with TMPDIR pointing to a new folder of its own, and removes that folder at the end. Every child process the suite starts (workers, mav run, mav open) inherits the variable, so the suite and its children share that folder and nothing outside it. The product code is unchanged, and there are no retries.

TestSimulatorLocksStayInsideTheSuite pins this: it fails if a test's lock path is in the machine's shared lock folder.

Evidence

Reproduced on main (268f7f0) with a test binary built from it. A lock held by another project, live PID, planted in the temp folder on SIM, CLAIM-RUNREUSE-001 and CLAIM-NORELAUNCH-001:

binary result over the 11 reported tests
main 11 / 11 FAIL (screenshot_controls_test.go:263: command failed, simclaim_test.go:606: … code=sim_locked … udid=CLAIM-NORELAUNCH-001)
this branch 11 / 11 PASS

A natural race with nothing planted, two test processes sharing one temp folder:

scenario main this branch
both claim tests in 2 processes at once, -count=4 each 13 of 16 runs FAIL (4.6–7.2 s, simclaim_test.go:564, :606, :610) 24 / 24 PASS
status bar test looped while a full suite runs 4 FAIL in 214 runs. The full suite also failed TestOpenClearStateRequiresInstallCommand with sim_locked … udid=SIM 0 FAIL in 196 runs, no sim_locked in the suite

Ablation of the guard test: with the Setenv removed, TestSimulatorLocksStayInsideTheSuite fails with «simulator locks are shared with the rest of the machine: lock=$TMPDIR/mav/sim-locks/sim.json». With it back, the test passes.

make check (GOFLAGS=-count=1), two copies of the tree at the same time, real $TMPDIR:

tree suites run in parallel pairs internal/mav
main (44b6152) 4 4 FAIL: every failure is one of the tests above (sim_locked, «command failed», simclaim_test.go:550/606/610)
this branch (2 rounds before and 2 after rebasing onto 44b6152) 8 6 ok. Both copies of 1 round failed TestExecStepShellDoesNotSurviveMav; see below

make check alone on this branch: ok.

TestExecStepShellDoesNotSurviveMav failed once: in the first parallel round, in both copies at the same moment, after its 15 s window. It does not use simulator locks. It passed in the other 3 parallel rounds on this branch (6 suites), in the 4 parallel main suites, and in 6 runs of two test processes side by side. I could not tie it to this change or reproduce it again, so this PR leaves it alone.

…ring simulator claims

Simulator locks live under os.TempDir() so every mav process of the user
sees a real claim. For the test suite that made them shared state with every
other go test on the machine: the fixtures reuse fixed UDIDs ("SIM" in
dozens of tests, CLAIM-<label>-001 from claimTestUDID, since t.TempDir's
base name is 001 in every process), so two suites at once took each other's
claims. Tests failed with sim_locked in 0.00s, or found the lock they had
just written removed or rewritten by the other suite's release.

TestMain now points TMPDIR at a directory of its own for the whole suite;
every child it starts inherits it. TestSimulatorLocksStayInsideTheSuite pins
it.
@bitomule
bitomule merged commit 6e3ea31 into main Dec 3, 2026
1 check passed
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