Skip to content

test: isolate takeover, containment and emulator tests from concurrent suites - #289

Merged
ElbertePlinio merged 9 commits into
mainfrom
fix/278-280-concurrent-suite-isolation
Oct 8, 2026
Merged

ElbertePlinio merged 9 commits into
mainfrom
fix/278-280-concurrent-suite-isolation

Conversation

@ElbertePlinio

@ElbertePlinio ElbertePlinio commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Three tests failed when two full suites ran on one host. Each fix is in test code only.

#278: the takeover workers now wait at a barrier and claim together. The winner holds the lease until every worker has tried. Each worker reports claim and release times, and the test asserts the loser's claim ended before the winner released. Starting the old worker 400 ms late gave two winners with no overlap, so the old failure was a timing assumption. Changing wx to w in takeover.ts makes the new test fail with two winners.

#279: after the refused cleanup, the victim and the supervisor exit and the scope cgroup is empty. A concurrent createContainmentScope then prunes it. The test now builds its scope in a private parent cgroup, as the probe and re-creation tests do. With a concurrent scope creator, the old test failed 10 of 10 runs at the reported line.

#280: the AVD home and port registry were already private to each run. The collisions came from host-wide TCP ports. The emulator test file now takes an abstract Unix socket lock in beforeAll, so a second run waits. The kernel frees the lock when its owner exits. The tests still use the real ports and exercise the real collision paths.

The third #280 failure, "refuses a writable start while a live emulator holds the AVD lock", came from the test, not from the port collisions. The test wrote the holder pid into the AVD lock right after the spawn event. Until the new image sets up its arguments, the kernel reports an empty cmdline, so the product read the lock as stale. The test now waits until the holder's cmdline shows emulator, and stops any emulator that starts by mistake. An experiment saw empty cmdline reads right after spawn in 3 of 3000 Node spawns under heavy load. The port lock now retries only on EADDRINUSE. The takeover worker also reports the raw lease when a loser sees a stale lease, which links such a failure to #298. If a test fails midway, the containment test now removes its private cgroups and reports any it cannot remove.

Closes #278
Closes #279
Closes #280
Closes #294

Requirement Verified by Scenario Result Evidence
#278 confirm whether the claims overlapped Manual experiment, automated test Old worker started 400 ms late; new worker with 600 ms spawn skew Old: 2 winners, no overlap. New: 1 winner, overlap asserted Worker log, /tmp/pfload
#278 workers claim together Automated test, mutation check wx changed to w in takeover.ts Test fails with 2 winners Worker log
#278 repeat runs under load Repeat runs 35 runs with the core suite looping; 30 runs with 32 CPU burners (load about 45) 65 of 65 passed /tmp/pfload
#279 find what removed the scope Manual experiment cgroup.procs and victim state recorded at the check; concurrent creator running Scope empty, victim dead; old test failed 10 of 10 /tmp/pf279
#279 assertion holds under a concurrent creator Automated test, repeat runs Private parent cgroup; concurrent creator; burners plus core suite loop 60 of 60 passed /tmp/pf279
#280 runs no longer take each other's ports Automated test, repeat runs 15 rounds of two concurrent copies of emulator.test.ts 29 of 30 passed. The one failure was the #210 give-up race /tmp/pf280
#280 / #294 AVD lock refusal (review round 1) Experiment, repeat runs Empty cmdline reads after spawn: Node 3 of 3000 under 48 busy loops; emulator.test.ts 10 runs under 16 busy loops Window confirmed; 10 of 10 passed, no fake emulator left ~/Artifacts/pickforge-batch2-2026-10-07/worker-cmdline-exp
Cleanup after a failed containment test (review round 1) Injected failure Failure injected after the victim joined, 5 single-CPU runs No private cgroup left Worker log
Repo checks lint, typecheck, build, PickCheck, coverage Final head dae1040 All pass; 2965 tests passed, thresholds hold ~/Artifacts/pickforge-batch2-2026-10-07/289-cov-final.log

QA device pass: skipped. The change is test code only, so there is nothing to drive.

Workers wait on a barrier before claiming, and a winner holds the lease
until every worker has attempted. Spawn skew can no longer turn the race
into two sequential claims. The test asserts the loser's attempt ended
before the winner released.

Closes #278
The refused cleanup still empties the scope, so a concurrent creator's
prune could remove it before the existence check.

Closes #279
The console ports are host-global and the TCP probe binds each port it
checks. An abstract Unix socket lock makes a second run of the file wait.

Closes #280
The locked-AVD test wrote the holder pid into the lock as soon as the
spawn event fired. Until exec sets up the new image, /proc reports an
empty cmdline, so startEmulator read the lock as stale and started the
fake emulator. The test now polls up to 5 s for "emulator" in the
holder's cmdline before it writes the lock. If a start wrongly succeeds,
the test stops that emulator before it fails.

The port lock now waits only on EADDRINUSE. Other listen errors fail
at once with their code instead of spinning for 120 s.

Closes #294
…ease

The race test still requires HumanLeaseHeldError for the loser. When the
loser gets StaleHumanLeaseError instead, the worker now reports the raw
lease content it read, and the assertion message shows it. This makes a
failure from the partly written lease window in #298 diagnosable.
@ElbertePlinio
ElbertePlinio merged commit d2b7b95 into main Oct 8, 2026
10 checks passed
@ElbertePlinio
ElbertePlinio deleted the fix/278-280-concurrent-suite-isolation branch October 8, 2026 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment