carlos / platform Public

test(activator): synchronize release and worker cleanup assertions

Run the lease-loss deadline test on synctest time so the deadline check
and settle timestamp cannot drift with runner load. Retry generations
reads during the sequence/file publication gap, and wait for the desired
pin state after the release record disappears. Drive the worker sweeper
until asynchronous proof and cleanup finish instead of relying on one
pass.

All changes are test-only; production code and root-read census unchanged.
The sweep-of-252 test is unchanged under the requested environment-only
exception: local durable DirStore writes are multiplied by its time scale.
It failed 6/6 baseline runs on this ext4 filesystem.

Validation across cpu=1,2,4: all four activator tests passed 60 runs each
and 9 race runs each. Baseline release lease-loss, release obligation and
awake-incumbent retry failed 15/15 each on generations-file races; worker
cleanup passed 15/15. The reported deadline and worker timeout failures
were not reproduced in that baseline. Edge counts are in the prior commits.
Whole-tree gofmt and diff checks, vet of activator and edge, go build ./...
and GOOS=darwin GOARCH=arm64 go build ./... passed. No full test suite run.

Independent Opus whole-branch review, round 1: READY, no P1 or P2; stopped
under the review budget. No production or census diff needs follow-up.
Deferred P3 follow-ups from that review:
- Restore a per-seed virtual shutdown watchdog in the simulation; current
  cancellation regressions fail through synctest deadlock or test timeout.
- Scope the simulation's stop defers per seed instead of retaining 300.
- Move the runnable-task comment immediately above synctest.Wait.
- Consolidate pinned/pinnedSettled or update the latter's caller description.
- Consider restoring automatic GOMAXPROCS adjustment after the Go 1.26
  race workaround; it currently restores the previous numeric value.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 3234b7b5b860895dc0d93af95997a0f403df5eda parent bc5e344
3 files changed, +88 −77
  • internal/activator/rootfs_wake_release_test.go +3 −3
  • internal/activator/rootfsrelease_test.go +75 −71
  • internal/activator/rootfsworkers_test.go +10 −3

CI cancelled — superseded by a newer push — run details

diff --git a/internal/activator/rootfs_wake_release_test.go b/internal/activator/rootfs_wake_release_test.go
index f177ffac8..ef5968c3c 100644
--- a/internal/activator/rootfs_wake_release_test.go
+++ b/internal/activator/rootfs_wake_release_test.go
@@ -1042,9 +1042,9 @@ func TestReleaseObligationRetriedUntilProven(t *testing.T) {
if p, l := r.index("release:proven:v2"), r.index("release-lease"); p < 0 || l < p {
t.Fatalf("order %v: the lease went back before the proof", r.b.events())
}
- if pinnedSettled(t, r.a, host, "v2") {
- t.Fatal("the generations file still names v2 after the proof")
- }
+ // The pin leaves the file after the record goes (releaseProven persists
+ // the generations once the record is deleted), so wait for it.
+ waitFor(t, "the pin to leave the generations file", func() bool { return !pinnedSettled(t, r.a, host, "v2") })
ch := r.wake(r.a)
r.nextUnit(t).done("exited", "0", "success")
if err := waitErr(t, ch); err != nil {
diff --git a/internal/activator/rootfsrelease_test.go b/internal/activator/rootfsrelease_test.go
index 0f2b75d69..847067577 100644
--- a/internal/activator/rootfsrelease_test.go
+++ b/internal/activator/rootfsrelease_test.go
@@ -24,6 +24,7 @@ import (
"sync"
"sync/atomic"
"testing"
+ "testing/synctest"
"time"
"github.com/carlosframework/platform/internal/hostclaim"
@@ -702,14 +703,11 @@ func (r *releaseRig) noRecord(t *testing.T, when string) {
}
// pinned reports whether the generations file on disk names build v under
-// the host.
+// the host. Publication writes the sequence marker before the generations
+// file, so pinnedSettled retries reads made between those two writes.
func pinned(t *testing.T, a *Service, host, v string) bool {
t.Helper()
- g, err := release.ReadGenerations(a.GenerationsFile)
- if err != nil {
- t.Fatalf("the generations file: %v", err)
- }
- return g != nil && slices.Contains(g.Hosts[host], v)
+ return pinnedSettled(t, a, host, v)
}
// shrinkRelease shrinks the lease lead, the recheck and the retries. Not
@@ -1139,72 +1137,78 @@ func TestReleaseKeepsRunningWhileTheLeaseRenews(t *testing.T) {
}
func TestReleaseLeaseLossUnprovenLeavesTheHold(t *testing.T) {
- shrinkRelease(t, 200*time.Millisecond, 10*time.Millisecond)
- r := newReleaseRig(t)
- until := time.Now().Add(800 * time.Millisecond)
- r.held = newOwnedLease(until, false)
- var stuck sync.Mutex
- isStuck := true
- r.b.unit.settle = func(int) error {
- stuck.Lock()
- defer stuck.Unlock()
- if isStuck {
- return errors.New("processes remained in the unit's cgroup")
+ // The settle loop, the supervisor and the lease deadline all read the real
+ // clock, so under load a settle could start after the deadline by sleep
+ // overshoot alone. A synctest bubble gives them one fake clock: sleeps are
+ // exact and the deadline comparison is deterministic.
+ synctest.Test(t, func(t *testing.T) {
+ shrinkRelease(t, 200*time.Millisecond, 10*time.Millisecond)
+ r := newReleaseRig(t)
+ until := time.Now().Add(800 * time.Millisecond)
+ r.held = newOwnedLease(until, false)
+ var stuck sync.Mutex
+ isStuck := true
+ r.b.unit.settle = func(int) error {
+ stuck.Lock()
+ defer stuck.Unlock()
+ if isStuck {
+ return errors.New("processes remained in the unit's cgroup")
+ }
+ return nil
}
- return nil
- }
- ch := r.run(context.Background())
- r.waitStarted(t)
- r.held.lose(lease.ErrLost)
- res := wait(t, ch)
- if !errors.Is(res.err, errReleaseUnproven) || !errors.Is(res.err, errSwapLeaseLost) {
- t.Fatalf("runRelease = %v, want errReleaseUnproven and errSwapLeaseLost", res.err)
- }
- if o := classifyRelease(res.err, true); o != releaseUnproven {
- t.Errorf("classified %v, want unproven", o)
- }
- stops := r.b.unit.stopTimes()
- if len(stops) < 2 {
- t.Errorf("the settle was tried %d times after the trip, want it retried until the deadline", len(stops))
- }
- if last := stops[len(stops)-1]; last.After(until) {
- t.Errorf("a settle began at %v, after the deadline %v", last, until)
- }
- op := r.record()
- if op == nil {
- t.Fatal("the record went with its unit unproven")
- }
- r.a.mu.Lock()
- state := op.state
- r.a.mu.Unlock()
- if state != releaseNotProven {
- t.Errorf("record state %d, want releaseNotProven (the reaper's)", state)
- }
- if evs := r.events(); slices.Contains(evs, fmt.Sprintf(rolloutwords.EventReleaseLeaseLost, "v2")) {
- t.Errorf("C29 with the unit unproven: %q", evs)
- }
- if !pinned(t, r.a, r.rt.Host, "v2") {
- t.Error("the generations file does not name v2 while its unit is unproven")
- }
- // The reaper owns it now: once the group empties, the sweep's pass
- // proves it.
- n := len(stops)
- r.a.mu.Lock()
- r.a.finishPendingStops()
- r.a.mu.Unlock()
- time.Sleep(50 * time.Millisecond)
- if got := len(r.b.unit.stopTimes()); got != n {
- t.Fatalf("the reaper retried %d times inside actStopTimeout", got-n)
- }
- stuck.Lock()
- isStuck = false
- stuck.Unlock()
- r.clk.advance(actStopTimeout)
- r.a.mu.Lock()
- r.a.finishPendingStops()
- r.a.mu.Unlock()
- waitFor(t, "the reaper's proof", func() bool { return r.record() == nil })
- waitFor(t, "the pin to go", func() bool { return !pinned(t, r.a, r.rt.Host, "v2") })
+ ch := r.run(context.Background())
+ r.waitStarted(t)
+ r.held.lose(lease.ErrLost)
+ res := wait(t, ch)
+ if !errors.Is(res.err, errReleaseUnproven) || !errors.Is(res.err, errSwapLeaseLost) {
+ t.Fatalf("runRelease = %v, want errReleaseUnproven and errSwapLeaseLost", res.err)
+ }
+ if o := classifyRelease(res.err, true); o != releaseUnproven {
+ t.Errorf("classified %v, want unproven", o)
+ }
+ stops := r.b.unit.stopTimes()
+ if len(stops) < 2 {
+ t.Errorf("the settle was tried %d times after the trip, want it retried until the deadline", len(stops))
+ }
+ if last := stops[len(stops)-1]; last.After(until) {
+ t.Errorf("a settle began at %v, after the deadline %v", last, until)
+ }
+ op := r.record()
+ if op == nil {
+ t.Fatal("the record went with its unit unproven")
+ }
+ r.a.mu.Lock()
+ state := op.state
+ r.a.mu.Unlock()
+ if state != releaseNotProven {
+ t.Errorf("record state %d, want releaseNotProven (the reaper's)", state)
+ }
+ if evs := r.events(); slices.Contains(evs, fmt.Sprintf(rolloutwords.EventReleaseLeaseLost, "v2")) {
+ t.Errorf("C29 with the unit unproven: %q", evs)
+ }
+ if !pinned(t, r.a, r.rt.Host, "v2") {
+ t.Error("the generations file does not name v2 while its unit is unproven")
+ }
+ // The reaper owns it now: once the group empties, the sweep's pass
+ // proves it.
+ n := len(stops)
+ r.a.mu.Lock()
+ r.a.finishPendingStops()
+ r.a.mu.Unlock()
+ time.Sleep(50 * time.Millisecond)
+ if got := len(r.b.unit.stopTimes()); got != n {
+ t.Fatalf("the reaper retried %d times inside actStopTimeout", got-n)
+ }
+ stuck.Lock()
+ isStuck = false
+ stuck.Unlock()
+ r.clk.advance(actStopTimeout)
+ r.a.mu.Lock()
+ r.a.finishPendingStops()
+ r.a.mu.Unlock()
+ waitFor(t, "the reaper's proof", func() bool { return r.record() == nil })
+ waitFor(t, "the pin to go", func() bool { return !pinned(t, r.a, r.rt.Host, "v2") })
+ })
}
func TestReleaseLeaseLossRacesExit(t *testing.T) {
diff --git a/internal/activator/rootfsworkers_test.go b/internal/activator/rootfsworkers_test.go
index 30bd37871..b9c7ec61b 100644
--- a/internal/activator/rootfsworkers_test.go
+++ b/internal/activator/rootfsworkers_test.go
@@ -918,9 +918,16 @@ func TestRootfsWorkerUnprovenKeepsItsFiles(t *testing.T) {
ctl.umu.Lock()
ctl.workerStopErr = nil
ctl.umu.Unlock()
- clk.advance(actStopTimeout)
- a.sweepOnce()
- waitFor(t, "the stop to finish", func() bool { return !a.hasEntry(rt.Host) })
+ // The pending state is visible while the stop's own proof attempt (the
+ // reap goroutine) may still be in flight against the error just cleared.
+ // A sweep that meets that attempt in flight skips the entry, and the
+ // attempt may have read the old error, so one sweep is not enough: each
+ // poll is a fresh sweep pass a stop-timeout later, until the proof holds.
+ waitFor(t, "the stop to finish", func() bool {
+ clk.advance(actStopTimeout)
+ a.sweepOnce()
+ return !a.hasEntry(rt.Host)
+ })
for _, f := range []string{launch, record} {
if _, err := os.Stat(f); !os.IsNotExist(err) {
t.Errorf("%s outlived the proof: %v", filepath.Base(f), err)