Repository navigation
Give the test suite a temp dir of its own so concurrent runs stop sharing simulator claims - #176
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Tests in
internal/mavfailed now and then on a Mac where othergo testruns were going at the same time, while CI on the same commit was green. Each one passed alone:TestStatusBarStepDoesNotOverwriteTheEvidenceTimestamp,TestScreenshotControlFlowActionsReachSimctland sevenTestOpen…/TestLaunch…tests failed in 0.00 s with «command failed».TestFlowOverExistingRunHoldsTheClaimThroughItsStepsandTestNoRelaunchOpenKeepsTheSessionClaimAlivefailed after 4–7 s with «the session must hold CLAIM-NORELAUNCH-001 …».TestFlowOpenIgnoresStaleCurrentRun,TestFlowRunContinuesExistingRunIDandTestFlowRunDoesNotStealLiveManualRunPointeralso failed with «command failed».Cause
Simulator locks live under
os.TempDir()/mav/sim-lockson 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.claimTestUDIDbuildsCLAIM-<label>-+filepath.Base(t.TempDir()). That base is001in every process, so two suites both useCLAIM-NORELAUNCH-001.When two suites run at once (two worktrees'
make check), one refuses withsim_lockedbecause the other's live run holdsSIM. 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
TestMainnow runs the suite withTMPDIRpointing 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.TestSimulatorLocksStayInsideTheSuitepins 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 onSIM,CLAIM-RUNREUSE-001andCLAIM-NORELAUNCH-001:screenshot_controls_test.go:263: command failed,simclaim_test.go:606: … code=sim_locked … udid=CLAIM-NORELAUNCH-001)A natural race with nothing planted, two test processes sharing one temp folder:
-count=4eachsimclaim_test.go:564,:606,:610)TestOpenClearStateRequiresInstallCommandwithsim_locked … udid=SIMsim_lockedin the suiteAblation of the guard test: with the
Setenvremoved,TestSimulatorLocksStayInsideTheSuitefails 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:internal/mavmain(44b6152)sim_locked, «command failed»,simclaim_test.go:550/606/610)TestExecStepShellDoesNotSurviveMav; see belowmake checkalone on this branch: ok.TestExecStepShellDoesNotSurviveMavfailed 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 parallelmainsuites, 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.