ci-flakes-1028
Squashed from ci-flakes-1028 into main.
36 files changed,
+392
−98
internal/activator/activator_test.go+38 −21internal/activator/backend_exec_test.go+2 −2internal/activator/binary_golden_test.go+2 −2internal/activator/exec_gate_test.go+5 −5internal/activator/execwrite_test.go+19 −0internal/activator/genbackend_test.go+7 −7internal/activator/generations_backend_test.go+2 −2internal/activator/gensocket_rev19_test.go+2 −2internal/activator/harelease_keep_test.go+1 −1internal/activator/harelease_test.go+35 −1internal/activator/identity_test.go+9 −9internal/activator/instancekey_test.go+1 −1internal/activator/replica_instancekey_test.go+1 −1internal/activator/rolelaunch_root_linux_test.go+1 −1internal/activator/swap_fixture_test.go+1 −1internal/activator/swap_sidecar_test.go+4 −4internal/activator/swap_sim_test.go+1 −1internal/activator/wakeidentity_test.go+1 −2internal/activator/wakeplan_test.go+2 −2internal/activator/wakerecord_refused_test.go+1 −1internal/activator/worker_generations_test.go+3 −3internal/activator/worker_staged_test.go+4 −4internal/console/claim_invariant_fixtures_test.go+1 −1internal/console/claim_invariant_world_test.go+10 −1internal/console/lifetimes_purge_test.go+14 −1internal/dbreads/fixture_test.go+12 −0internal/dbreads/loop_test.go+7 −1internal/dbreads/read_test.go+14 −2internal/host/applylock_linux_test.go+49 −0internal/host/applylock_other_test.go+9 −0internal/host/caps_pass_test.go+43 −0internal/host/installchannel_policy_test.go+1 −0internal/host/movesoffline_stage_test.go+10 −2internal/host/movesphase1_test.go+40 −15internal/rollout/fake_test.go+9 −0internal/rollout/holdran_test.go+31 −2
CI passed — run details
diff --git a/internal/activator/activator_test.go b/internal/activator/activator_test.go| index 49684b033..32c0e5d65 100644 |
| --- a/internal/activator/activator_test.go |
| +++ b/internal/activator/activator_test.go |
| @@ -4661,7 +4661,7 @@ func stageLive(t *testing.T, b *ExecBackend, host, ver string) { |
| t.Fatal(err) |
| } |
| bin := filepath.Join(vdir, "app") |
| - if err := os.WriteFile(bin, []byte("#!/bin/sh\n"), 0o755); err != nil { |
| + if err := writeExecutable(bin, []byte("#!/bin/sh\n"), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| if err := os.MkdirAll(filepath.Join(b.OptDir, "live"), 0o755); err != nil { |
| @@ -4773,7 +4773,7 @@ func stageLiveUnderAccount(t *testing.T, optDir, host, acct, ver, app string) { |
| if err := os.MkdirAll(dir, 0o755); err != nil { |
| t.Fatal(err) |
| } |
| - if err := os.WriteFile(filepath.Join(dir, app), []byte("bin"), 0o755); err != nil { |
| + if err := writeExecutable(filepath.Join(dir, app), []byte("bin"), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| if err := os.MkdirAll(filepath.Join(optDir, "live"), 0o755); err != nil { |
| @@ -5011,7 +5011,7 @@ func TestExecBackendStartWorkerEnvWinsOverTenantFile(t *testing.T) { |
| defer p.Stop(context.Background()) |
| child := map[string]string{} |
| - for _, line := range strings.Split(waitForFile(t, envPath, time.Second), "\n") { |
| + for _, line := range strings.Split(waitForFileContent(t, envPath, time.Second), "\n") { |
| if k, v, ok := strings.Cut(line, "="); ok { |
| child[k] = v |
| } |
| @@ -5075,7 +5075,7 @@ func stageRecordingLive(t *testing.T, b *ExecBackend, host, ver string) (argvPat |
| t.Fatal(err) |
| } |
| bin := filepath.Join(vdir, "app") |
| - if err := os.WriteFile(bin, []byte(script), 0o755); err != nil { |
| + if err := writeExecutable(bin, []byte(script), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| if err := os.MkdirAll(filepath.Join(b.OptDir, "live"), 0o755); err != nil { |
| @@ -5108,7 +5108,7 @@ func stageRecordingLiveFullEnv(t *testing.T, b *ExecBackend, host, ver string) ( |
| t.Fatal(err) |
| } |
| bin := filepath.Join(vdir, "app") |
| - if err := os.WriteFile(bin, []byte(script), 0o755); err != nil { |
| + if err := writeExecutable(bin, []byte(script), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| if err := os.MkdirAll(filepath.Join(b.OptDir, "live"), 0o755); err != nil { |
| @@ -5124,10 +5124,27 @@ func stageRecordingLiveFullEnv(t *testing.T, b *ExecBackend, host, ver string) ( |
| // waitForFile polls until path exists (the child writes it concurrently with |
| // Start's health wait) and returns its contents. |
| func waitForFile(t *testing.T, path string, within time.Duration) string { |
| + t.Helper() |
| + return waitForFileWhere(t, path, within, func([]byte) bool { return true }) |
| +} |
| + |
| +// waitForFileContent is waitForFile for a file whose contents the test |
| +// reads: it waits until the file has something in it. Existing is not |
| +// enough there: the child's shell creates the file for its redirect before |
| +// printf writes to it, and a read in between saw "" (a CI-load repro, |
| +// TestExecBackendStartStagedRunsAForeignRowOnItsCanonicalSocket). Every |
| +// recorder whose contents are read writes at least a newline or a path, in |
| +// one write. A marker that is only touched is waited for with waitForFile. |
| +func waitForFileContent(t *testing.T, path string, within time.Duration) string { |
| + t.Helper() |
| + return waitForFileWhere(t, path, within, func(b []byte) bool { return len(b) > 0 }) |
| +} |
| + |
| +func waitForFileWhere(t *testing.T, path string, within time.Duration, ok func([]byte) bool) string { |
| t.Helper() |
| deadline := time.Now().Add(within) |
| for time.Now().Before(deadline) { |
| - if b, err := os.ReadFile(path); err == nil { |
| + if b, err := os.ReadFile(path); err == nil && ok(b) { |
| return string(b) |
| } |
| time.Sleep(10 * time.Millisecond) |
| @@ -5192,8 +5209,8 @@ func TestExecBackendStartPassesControlSocketInEnvAndStartsPurgeListener(t *testi |
| time.Sleep(10 * time.Millisecond) |
| } |
| - gotArgv := strings.Fields(waitForFile(t, argvPath, time.Second)) |
| - gotEnv := strings.TrimSpace(waitForFile(t, envPath, time.Second)) |
| + gotArgv := strings.Fields(waitForFileContent(t, argvPath, time.Second)) |
| + gotEnv := strings.TrimSpace(waitForFileContent(t, envPath, time.Second)) |
| // Everything above was seen while the health wait ran; the fake never |
| // binds, so end the wait rather than sit out its timeout. |
| @@ -5265,7 +5282,7 @@ func TestExecBackendStartWithNilCacheStillBindsControlSocket(t *testing.T) { |
| time.Sleep(10 * time.Millisecond) |
| } |
| child := map[string]string{} |
| - for _, line := range strings.Split(waitForFile(t, envPath, time.Second), "\n") { |
| + for _, line := range strings.Split(waitForFileContent(t, envPath, time.Second), "\n") { |
| if k, v, ok := strings.Cut(line, "="); ok { |
| child[k] = v |
| } |
| @@ -5469,7 +5486,7 @@ func TestExecBackendStartMergesConfigEnvUnderOwnEnv(t *testing.T) { |
| } |
| child := map[string]string{} |
| - for _, line := range strings.Split(waitForFile(t, envPath, time.Second), "\n") { |
| + for _, line := range strings.Split(waitForFileContent(t, envPath, time.Second), "\n") { |
| if k, v, ok := strings.Cut(line, "="); ok { |
| child[k] = v |
| } |
| @@ -5516,7 +5533,7 @@ func TestExecBackendStartAdvertisesHeaderPurgeChannel(t *testing.T) { |
| } |
| child := map[string]string{} |
| - for _, line := range strings.Split(waitForFile(t, envPath, time.Second), "\n") { |
| + for _, line := range strings.Split(waitForFileContent(t, envPath, time.Second), "\n") { |
| if k, v, ok := strings.Cut(line, "="); ok { |
| child[k] = v |
| } |
| @@ -5527,7 +5544,7 @@ func TestExecBackendStartAdvertisesHeaderPurgeChannel(t *testing.T) { |
| if got := child["CARLOS_CONTROL_SOCKET"]; got != rt.Socket+".control" { |
| t.Fatalf("child CARLOS_CONTROL_SOCKET = %q, want %q — the header channel is ADDITIONAL, it does not replace the socket", got, rt.Socket+".control") |
| } |
| - gotArgv := strings.Fields(waitForFile(t, argvPath, time.Second)) |
| + gotArgv := strings.Fields(waitForFileContent(t, argvPath, time.Second)) |
| wantArgv := []string{"--socket", rt.Socket, "--db", filepath.Join(b.DataDir, rt.Host+".db")} |
| if !slices.Equal(gotArgv, wantArgv) { |
| t.Fatalf("child argv = %v, want %v — a flag the app binary doesn't parse makes it exit 2 at startup", gotArgv, wantArgv) |
| @@ -5554,7 +5571,7 @@ func TestExecBackendStartWithNilCacheSetsNoPurgeVar(t *testing.T) { |
| defer proc.Stop(context.Background()) |
| } |
| - for _, line := range strings.Split(waitForFile(t, envPath, time.Second), "\n") { |
| + for _, line := range strings.Split(waitForFileContent(t, envPath, time.Second), "\n") { |
| if k, _, ok := strings.Cut(line, "="); ok && k == "CARLOS_PURGE" { |
| t.Fatalf("child saw %q with no cache configured", line) |
| } |
| @@ -5600,7 +5617,7 @@ func TestExecBackendStartTenantCannotClaimAbsentPurgeChannel(t *testing.T) { |
| } |
| child := map[string]string{} |
| - for _, line := range strings.Split(waitForFile(t, envPath, time.Second), "\n") { |
| + for _, line := range strings.Split(waitForFileContent(t, envPath, time.Second), "\n") { |
| if k, v, ok := strings.Cut(line, "="); ok { |
| child[k] = v |
| } |
| @@ -5648,7 +5665,7 @@ func TestExecBackendStartOverridesTenantSuppliedPurgeVars(t *testing.T) { |
| } |
| child := map[string]string{} |
| - for _, line := range strings.Split(waitForFile(t, envPath, time.Second), "\n") { |
| + for _, line := range strings.Split(waitForFileContent(t, envPath, time.Second), "\n") { |
| if k, v, ok := strings.Cut(line, "="); ok { |
| child[k] = v |
| } |
| @@ -5722,7 +5739,7 @@ func stageSeedScript(t *testing.T, b *ExecBackend, host, ver, body string) { |
| t.Fatal(err) |
| } |
| bin := filepath.Join(vdir, "app") |
| - if err := os.WriteFile(bin, []byte("#!/bin/sh\n"+body), 0o755); err != nil { |
| + if err := writeExecutable(bin, []byte("#!/bin/sh\n"+body), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| if err := os.MkdirAll(filepath.Join(b.OptDir, "live"), 0o755); err != nil { |
| @@ -5914,14 +5931,14 @@ func TestExecBackendSeedRunsDeclaredArgvWithDBPath(t *testing.T) { |
| t.Fatalf("Seed: %v", err) |
| } |
| - gotArgv := strings.Fields(waitForFile(t, argvPath, time.Second)) |
| + gotArgv := strings.Fields(waitForFileContent(t, argvPath, time.Second)) |
| wantArgv := []string{"seed", "--fixtures", "--db", filepath.Join(b.DataDir, host+".db")} |
| if !slices.Equal(gotArgv, wantArgv) { |
| t.Fatalf("seed argv = %v, want %v", gotArgv, wantArgv) |
| } |
| child := map[string]string{} |
| - for _, line := range strings.Split(waitForFile(t, envPath, time.Second), "\n") { |
| + for _, line := range strings.Split(waitForFileContent(t, envPath, time.Second), "\n") { |
| if k, v, ok := strings.Cut(line, "="); ok { |
| child[k] = v |
| } |
| @@ -5960,7 +5977,7 @@ func TestExecBackendSeedHonoursRouteDBPath(t *testing.T) { |
| if err := b.Seed(context.Background(), registry.Route{Host: host, Kind: "instance", DBPath: dbPath, Seed: `["seed"]`}); err != nil { |
| t.Fatalf("Seed: %v", err) |
| } |
| - gotArgv := strings.Fields(waitForFile(t, argvPath, time.Second)) |
| + gotArgv := strings.Fields(waitForFileContent(t, argvPath, time.Second)) |
| wantArgv := []string{"seed", "--db", dbPath} |
| if !slices.Equal(gotArgv, wantArgv) { |
| t.Fatalf("seed argv = %v, want %v", gotArgv, wantArgv) |
| @@ -6316,7 +6333,7 @@ func TestExecBackendDoesNotNormalizeSquatterSocket(t *testing.T) { |
| t.Fatal(err) |
| } |
| bin := filepath.Join(vdir, "app") |
| - if err := os.WriteFile(bin, []byte(script), 0o755); err != nil { |
| + if err := writeExecutable(bin, []byte(script), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| if err := os.MkdirAll(filepath.Join(b.OptDir, "live"), 0o755); err != nil { |
| @@ -6397,7 +6414,7 @@ func TestChildProcStopKeepsTheControlSocketUpUntilTheChildExits(t *testing.T) { |
| "touch '" + ready + "'\n" + |
| "while [ ! -f '" + release + "' ]; do sleep 0.02; done\n" + |
| "exit 0\n" |
| - if err := os.WriteFile(script, []byte(body), 0o755); err != nil { |
| + if err := writeExecutable(script, []byte(body), 0o755); err != nil { |
| t.Fatal(err) |
| } |
diff --git a/internal/activator/backend_exec_test.go b/internal/activator/backend_exec_test.go| index 23a334b10..908535fc4 100644 |
| --- a/internal/activator/backend_exec_test.go |
| +++ b/internal/activator/backend_exec_test.go |
| @@ -222,7 +222,7 @@ func TestExecBackendStartChildRegion(t *testing.T) { |
| defer proc.Stop(context.Background()) |
| } |
| child := map[string]string{} |
| - for _, line := range strings.Split(waitForFile(t, envPath, time.Second), "\n") { |
| + for _, line := range strings.Split(waitForFileContent(t, envPath, time.Second), "\n") { |
| if k, v, ok := strings.Cut(line, "="); ok { |
| child[k] = v |
| } |
| @@ -254,7 +254,7 @@ func TestExecBackendStartChildHandsTheHost(t *testing.T) { |
| defer proc.Stop(context.Background()) |
| } |
| child := map[string]string{} |
| - for _, line := range strings.Split(waitForFile(t, envPath, time.Second), "\n") { |
| + for _, line := range strings.Split(waitForFileContent(t, envPath, time.Second), "\n") { |
| if k, v, ok := strings.Cut(line, "="); ok { |
| child[k] = v |
| } |
diff --git a/internal/activator/binary_golden_test.go b/internal/activator/binary_golden_test.go| index 428c5a943..4a6166133 100644 |
| --- a/internal/activator/binary_golden_test.go |
| +++ b/internal/activator/binary_golden_test.go |
| @@ -224,7 +224,7 @@ func TestBinaryStartStagedGolden(t *testing.T) { |
| if err := os.MkdirAll(filepath.Dir(v2), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| - if err := os.WriteFile(v2, []byte("#!/bin/sh\nprintf '%s\\n' \"$0\" \"$@\" > '"+marker+"'\nexec sleep 30\n"), 0o755); err != nil { |
| + if err := writeExecutable(v2, []byte("#!/bin/sh\nprintf '%s\\n' \"$0\" \"$@\" > '"+marker+"'\nexec sleep 30\n"), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| rt := registry.Route{Host: host, Kind: "instance", DBPath: filepath.Join(b.DataDir, host+".db"), |
| @@ -234,7 +234,7 @@ func TestBinaryStartStagedGolden(t *testing.T) { |
| t.Fatalf("StartStaged: %v", err) |
| } |
| defer proc.Stop(context.Background()) //nolint:errcheck |
| - argv := waitForFile(t, marker, 2*time.Second) |
| + argv := waitForFileContent(t, marker, 2*time.Second) |
| roots := map[string]string{b.OptDir: "$OPT", b.DataDir: "$DATA", b.RunDirOverride: "$RUN"} |
| raw, err := json.MarshalIndent(g, "", " ") |
| if err != nil { |
diff --git a/internal/activator/exec_gate_test.go b/internal/activator/exec_gate_test.go| index 30a5f99ee..4499ede11 100644 |
| --- a/internal/activator/exec_gate_test.go |
| +++ b/internal/activator/exec_gate_test.go |
| @@ -701,7 +701,7 @@ func TestALiveExecGateGatesTheFlatLiveLinkSpawn(t *testing.T) { |
| t.Fatalf("spawn = %v", err) |
| } |
| defer p.Stop(context.Background()) |
| - if got := strings.TrimSpace(waitForFile(t, out, 5*time.Second)); got != v1 { |
| + if got := strings.TrimSpace(waitForFileContent(t, out, 5*time.Second)); got != v1 { |
| t.Fatalf("$0 = %q, want the staged v1 the gate was asked about (%s)", got, v1) |
| } |
| if ver != "v1" || !slices.Equal(g.builds(), []string{"v1"}) { |
| @@ -738,7 +738,7 @@ func TestALiveExecGateGatesTheFlatLiveLinkSpawn(t *testing.T) { |
| t.Fatalf("spawn = %v", err) |
| } |
| defer p.Stop(context.Background()) |
| - if got := strings.TrimSpace(waitForFile(t, out, 5*time.Second)); got != b.liveLink(rt.Host) || ver != "v1" { |
| + if got := strings.TrimSpace(waitForFileContent(t, out, 5*time.Second)); got != b.liveLink(rt.Host) || ver != "v1" { |
| t.Fatalf("$0 = %q, version %q; want today's exec of %s, v1", got, ver, b.liveLink(rt.Host)) |
| } |
| }) |
| @@ -803,7 +803,7 @@ func TestALiveExecGateGatesAWorkerSpawnFromTheLiveLink(t *testing.T) { |
| t.Fatalf("recycle onto the captured v1 = %v", err) |
| } |
| defer p.Stop(context.Background()) |
| - if id != onto || strings.TrimSpace(waitForFile(t, out, 5*time.Second)) != v1 { |
| + if id != onto || strings.TrimSpace(waitForFileContent(t, out, 5*time.Second)) != v1 { |
| t.Fatalf("recycled %+v, want the captured v1", id) |
| } |
| if !slices.Equal(g.builds(), []string{"v2"}) { |
| @@ -956,7 +956,7 @@ func TestALiveExecGateGatesTheLegacySidecarStart(t *testing.T) { |
| t.Fatalf("StartSidecar = %v", err) |
| } |
| defer p.Stop(context.Background()) |
| - if got := strings.TrimSpace(waitForFile(t, out, 5*time.Second)); got != v1 { |
| + if got := strings.TrimSpace(waitForFileContent(t, out, 5*time.Second)); got != v1 { |
| t.Fatalf("sidecar $0 = %q, want the staged v1 the gate was asked about (%s)", got, v1) |
| } |
| if !slices.Equal(g.builds(), []string{"v1"}) { |
| @@ -988,7 +988,7 @@ func TestALiveExecGateGatesTheLegacySidecarStart(t *testing.T) { |
| t.Fatalf("StartSidecar = %v", err) |
| } |
| defer p.Stop(context.Background()) |
| - if got := strings.TrimSpace(waitForFile(t, out, 5*time.Second)); got != b.liveLink(rt.Host) { |
| + if got := strings.TrimSpace(waitForFileContent(t, out, 5*time.Second)); got != b.liveLink(rt.Host) { |
| t.Fatalf("sidecar $0 = %q, want today's exec of %s", got, b.liveLink(rt.Host)) |
| } |
| }) |
diff --git a/internal/activator/execwrite_test.go b/internal/activator/execwrite_test.go| new file mode 100644 |
| index 000000000..4f7edafb1 |
| --- /dev/null |
| +++ b/internal/activator/execwrite_test.go |
| @@ -0,0 +1,19 @@ |
| +package activator |
| + |
| +import ( |
| + "os" |
| + "syscall" |
| +) |
| + |
| +// writeExecutable is os.WriteFile for a file a test will exec. It holds |
| +// syscall.ForkLock for reading while the file is open for writing, so no |
| +// other goroutine can fork in that window. Without it, a parallel test's |
| +// fork could inherit the write descriptor and keep it until its child |
| +// execs, and an exec of this file in between fails with ETXTBSY ("text |
| +// file busy", CI 2026-10-27, TestExecBackendStartSidecarGen; Go issue |
| +// 22315). |
| +func writeExecutable(name string, data []byte, perm os.FileMode) error { |
| + syscall.ForkLock.RLock() |
| + defer syscall.ForkLock.RUnlock() |
| + return os.WriteFile(name, data, perm) |
| +} |
diff --git a/internal/activator/genbackend_test.go b/internal/activator/genbackend_test.go| index 5dac8fc54..ade597785 100644 |
| --- a/internal/activator/genbackend_test.go |
| +++ b/internal/activator/genbackend_test.go |
| @@ -22,7 +22,7 @@ import ( |
| func TestVerifyStaged(t *testing.T) { |
| dir := t.TempDir() |
| bin := filepath.Join(dir, "app") |
| - if err := os.WriteFile(bin, []byte("build v2"), 0o755); err != nil { |
| + if err := writeExecutable(bin, []byte("build v2"), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| sum := sha256.Sum256([]byte("build v2")) |
| @@ -113,7 +113,7 @@ func TestExecBackendStartStagedExecsTheStagedPath(t *testing.T) { |
| if err := os.MkdirAll(filepath.Dir(v2), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| - if err := os.WriteFile(v2, []byte("#!/bin/sh\nprintf '%s' \"$0\" > '"+marker+"'\n"), 0o755); err != nil { |
| + if err := writeExecutable(v2, []byte("#!/bin/sh\nprintf '%s' \"$0\" > '"+marker+"'\n"), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| rt := registry.Route{Host: host, Kind: "instance", DBPath: filepath.Join(b.DataDir, host+".db"), |
| @@ -123,7 +123,7 @@ func TestExecBackendStartStagedExecsTheStagedPath(t *testing.T) { |
| t.Fatalf("StartStaged: %v", err) |
| } |
| defer proc.Stop(context.Background()) //nolint:errcheck |
| - if got := waitForFile(t, marker, 2*time.Second); got != v2 { |
| + if got := waitForFileContent(t, marker, 2*time.Second); got != v2 { |
| t.Fatalf("the generation execd %q, want the staged %q", got, v2) |
| } |
| } |
| @@ -143,7 +143,7 @@ func TestExecBackendStartStagedReturnsTheProcessAtOnce(t *testing.T) { |
| if err := os.MkdirAll(filepath.Dir(v2), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| - if err := os.WriteFile(v2, []byte("#!/bin/sh\nexec sleep 30\n"), 0o755); err != nil { // never binds |
| + if err := writeExecutable(v2, []byte("#!/bin/sh\nexec sleep 30\n"), 0o755); err != nil { // never binds |
| t.Fatal(err) |
| } |
| rt := registry.Route{Host: host, Kind: "instance", DBPath: filepath.Join(b.DataDir, host+".db"), |
| @@ -187,7 +187,7 @@ func TestExecBackendStartStagedRunsAForeignRowOnItsCanonicalSocket(t *testing.T) |
| if err := os.MkdirAll(filepath.Dir(v2), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| - if err := os.WriteFile(v2, []byte("#!/bin/sh\nprintf '%s' \"$0\" > '"+marker+"'\n"), 0o755); err != nil { |
| + if err := writeExecutable(v2, []byte("#!/bin/sh\nprintf '%s' \"$0\" > '"+marker+"'\n"), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| rt := registry.Route{Host: host, Kind: "instance", DBPath: filepath.Join(b.DataDir, host+".db"), |
| @@ -203,7 +203,7 @@ func TestExecBackendStartStagedRunsAForeignRowOnItsCanonicalSocket(t *testing.T) |
| if g.Socket != rt.Socket || g.Control != rt.Socket+".control" { |
| t.Fatalf("foreign generation sockets %q %q, want the canonical %q", g.Socket, g.Control, rt.Socket) |
| } |
| - if got := waitForFile(t, marker, 2*time.Second); got != v2 { |
| + if got := waitForFileContent(t, marker, 2*time.Second); got != v2 { |
| t.Fatalf("the generation execd %q, want the staged %q", got, v2) |
| } |
| } |
| @@ -218,7 +218,7 @@ func TestExecBackendStartStagedClearsALeftoverCanonicalLink(t *testing.T) { |
| if err := os.MkdirAll(filepath.Dir(v2), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| - if err := os.WriteFile(v2, []byte("#!/bin/sh\nexec sleep 30\n"), 0o755); err != nil { |
| + if err := writeExecutable(v2, []byte("#!/bin/sh\nexec sleep 30\n"), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| rt := registry.Route{Host: host, Kind: "instance", DBPath: filepath.Join(b.DataDir, host+".db"), |
diff --git a/internal/activator/generations_backend_test.go b/internal/activator/generations_backend_test.go| index d8c57d8ff..34740c044 100644 |
| --- a/internal/activator/generations_backend_test.go |
| +++ b/internal/activator/generations_backend_test.go |
| @@ -64,8 +64,8 @@ func TestStartGenWithGenerationsOffIsStart(t *testing.T) { |
| proc, _, _ = b.StartGen(ctx, rt, 5, false) // the recorder never binds; a health error is expected |
| close(done) |
| }() |
| - gotArgv := strings.Fields(waitForFile(t, argvPath, time.Second)) |
| - gotEnv := strings.TrimSpace(waitForFile(t, envPath, time.Second)) |
| + gotArgv := strings.Fields(waitForFileContent(t, argvPath, time.Second)) |
| + gotEnv := strings.TrimSpace(waitForFileContent(t, envPath, time.Second)) |
| cancel() // recorded: end the health wait the recorder never answers |
| <-done |
| if proc != nil { |
diff --git a/internal/activator/gensocket_rev19_test.go b/internal/activator/gensocket_rev19_test.go| index 42a64b2c1..f4fa1ced7 100644 |
| --- a/internal/activator/gensocket_rev19_test.go |
| +++ b/internal/activator/gensocket_rev19_test.go |
| @@ -116,8 +116,8 @@ func TestFlatGenerationLaunchMatchesTheFlagOffLaunch(t *testing.T) { |
| proc, g, _ = b.StartGen(ctx, rt, n, perGen) // the recorder never binds; a health error is expected |
| close(done) |
| }() |
| - argv := strings.Split(strings.TrimSpace(waitForFile(t, argvPath, 3*time.Second)), "\n") |
| - env := envMap(t, strings.Split(strings.TrimSpace(waitForFile(t, envPath, 3*time.Second)), "\n")) |
| + argv := strings.Split(strings.TrimSpace(waitForFileContent(t, argvPath, 3*time.Second)), "\n") |
| + env := envMap(t, strings.Split(strings.TrimSpace(waitForFileContent(t, envPath, 3*time.Second)), "\n")) |
| cancel() // recorded: end the health wait the recorder never answers |
| <-done |
| if proc != nil { |
diff --git a/internal/activator/harelease_keep_test.go b/internal/activator/harelease_keep_test.go| index 400cc742b..8788141a9 100644 |
| --- a/internal/activator/harelease_keep_test.go |
| +++ b/internal/activator/harelease_keep_test.go |
| @@ -36,7 +36,7 @@ func TestLargeManifestReleaseThenKeep(t *testing.T) { |
| if _, err := s.wakeForTest(context.Background()); err != nil { |
| t.Fatal(err) |
| } |
| - reqs := s.fx.Requests()[n:] |
| + reqs := s.wakePathRequests(s.fx.Requests()[n:]) |
| if restoreCalls(s.b) != 0 || strings.Join(reqs, ",") != "GET "+lock+",PUT "+lock { |
| t.Fatalf("a kept wake with a large manifest made %v (%d restores)", reqs, restoreCalls(s.b)) |
| } |
diff --git a/internal/activator/harelease_test.go b/internal/activator/harelease_test.go| index 2d96a625b..750ea14c1 100644 |
| --- a/internal/activator/harelease_test.go |
| +++ b/internal/activator/harelease_test.go |
| @@ -837,7 +837,7 @@ func TestHAWakeRequestCounts(t *testing.T) { |
| if err != nil { |
| t.Fatal(err) |
| } |
| - return e, s.fx.Requests()[n:] |
| + return e, s.wakePathRequests(s.fx.Requests()[n:]) |
| } |
| e, reqs := wake() |
| // A first wake: the lock's three, then the launch's publish of its |
| @@ -871,6 +871,40 @@ func TestHAWakeRequestCounts(t *testing.T) { |
| } |
| } |
| +// wakePathRequests is reqs without the replica's level listings |
| +// ("LIST <host>/0001/" ... "LIST <host>/0009/"). Those are litestream's |
| +// compaction and snapshot monitors, which the store starts in goroutines |
| +// of their own when the wake opens it: they list their level once at |
| +// start, whenever they are scheduled, so on a loaded runner they land |
| +// before the wake returns and otherwise after it (CI, 2026-10-26 and |
| +// 2026-10-27). They are replication's requests, not the wake's, and |
| +// counting them made the wake's budget depend on the scheduler. |
| +func (s *haSvc) wakePathRequests(reqs []string) []string { |
| + prefix := s.b.Cfg.hibernatePrefix(s.rt.Host) + "/" |
| + var out []string |
| + for _, r := range reqs { |
| + if level, ok := strings.CutPrefix(r, "LIST "+prefix); ok && isReplicaLevelDir(level) { |
| + continue |
| + } |
| + out = append(out, r) |
| + } |
| + return out |
| +} |
| + |
| +// isReplicaLevelDir reports whether rel is one of litestream's level |
| +// directories as a listing names it: four digits and a slash. |
| +func isReplicaLevelDir(rel string) bool { |
| + if len(rel) != 5 || rel[4] != '/' { |
| + return false |
| + } |
| + for _, c := range rel[:4] { |
| + if c < '0' || c > '9' { |
| + return false |
| + } |
| + } |
| + return true |
| +} |
| + |
| // I1, the failed wake (final review F1): the tracked invocation is gone, |
| // replaced by a foreign one (unitproc's observer counts a replacement after |
| // the stop as the old one's exit), but the host's slice still holds it. No |
diff --git a/internal/activator/identity_test.go b/internal/activator/identity_test.go| index 23ea4b384..b24b305ea 100644 |
| --- a/internal/activator/identity_test.go |
| +++ b/internal/activator/identity_test.go |
| @@ -29,7 +29,7 @@ func stageVersion(t *testing.T, b *ExecBackend, host, ver, body string) string { |
| if err := os.MkdirAll(filepath.Dir(bin), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| - if err := os.WriteFile(bin, []byte("#!/bin/sh\n# "+ver+"\n"+body), 0o755); err != nil { |
| + if err := writeExecutable(bin, []byte("#!/bin/sh\n# "+ver+"\n"+body), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| repointLiveLink(t, b, host, bin) |
| @@ -152,7 +152,7 @@ func TestStartGenExeFlatExecsTheRecordedFile(t *testing.T) { |
| t.Fatalf("StartGenExe: %v", err) |
| } |
| defer proc.Stop(context.Background()) //nolint:errcheck |
| - if got := waitForFile(t, marker, 2*time.Second); got != a { |
| + if got := waitForFileContent(t, marker, 2*time.Second); got != a { |
| t.Fatalf("execd %q, want the recorded %q", got, a) |
| } |
| // No TierOf here, so the build's tier is GenTier's fallback, the default. |
| @@ -208,7 +208,7 @@ func TestStartGenExeFlatPerGenBindsTheGenerationSocket(t *testing.T) { |
| if g.Socket != own || g.Control != own+".control" || !isSocket(own) { |
| t.Fatalf("handle = %+v, want generation 9's bound socket %s", g, own) |
| } |
| - if got := waitForFile(t, marker, 2*time.Second); got != a { |
| + if got := waitForFileContent(t, marker, 2*time.Second); got != a { |
| t.Fatalf("execd %q, want the recorded %q", got, a) |
| } |
| if _, err := os.Lstat(rt.Socket); !os.IsNotExist(err) { |
| @@ -243,7 +243,7 @@ func TestStartGenExeForeignRunsOnTheCanonicalSocket(t *testing.T) { |
| if g.Socket != rt.Socket || g.Build != "vA" { |
| t.Fatalf("handle = %+v, want vA on the canonical %s", g, rt.Socket) |
| } |
| - if got := waitForFile(t, marker, 2*time.Second); got != a { |
| + if got := waitForFileContent(t, marker, 2*time.Second); got != a { |
| t.Fatalf("execd %q, want the recorded %q", got, a) |
| } |
| } |
| @@ -265,7 +265,7 @@ func TestSeedExeFlatRunsTheRecordedFile(t *testing.T) { |
| if err := b.SeedExe(context.Background(), rt, id); err != nil { |
| t.Fatalf("SeedExe: %v", err) |
| } |
| - if got := waitForFile(t, marker, time.Second); got != a { |
| + if got := waitForFileContent(t, marker, time.Second); got != a { |
| t.Fatalf("seeded with %q, want the recorded %q", got, a) |
| } |
| @@ -282,7 +282,7 @@ func TestSeedExeFlatRunsTheRecordedFile(t *testing.T) { |
| if err := b.Seed(context.Background(), rt); err != nil { |
| t.Fatalf("Seed: %v", err) |
| } |
| - if got := waitForFile(t, marker, time.Second); got != b.liveLink(host) { |
| + if got := waitForFileContent(t, marker, time.Second); got != b.liveLink(host) { |
| t.Fatalf("Seed ran %q, want the live link (today's, which resolves to %s)", got, bPath) |
| } |
| } |
| @@ -566,7 +566,7 @@ func TestADeclinedLinkOutsideTheStoreAsksRootForNothing(t *testing.T) { |
| b.Control = identityControl{ctl} |
| rt.Seed = `["seed"]` |
| hand := filepath.Join(t.TempDir(), "app") |
| - if err := os.WriteFile(hand, []byte("#!/bin/sh\nexit 0\n"), 0o755); err != nil { |
| + if err := writeExecutable(hand, []byte("#!/bin/sh\nexit 0\n"), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| repointLiveLink(t, b, rt.Host, hand) |
| @@ -610,7 +610,7 @@ func TestADeclinedFlatSeedRunsThePinnedFile(t *testing.T) { |
| if err := b.Seed(context.Background(), rt); err != nil { |
| t.Fatalf("Seed: %v", err) |
| } |
| - if got := waitForFile(t, marker, time.Second); got != v1 { |
| + if got := waitForFileContent(t, marker, time.Second); got != v1 { |
| t.Fatalf("seeded with %q, want the pinned %q", got, v1) |
| } |
| if got := g.builds(); !slices.Equal(got, []string{"v1"}) { |
| @@ -689,7 +689,7 @@ func TestBuildIdentityNamesTheStagedCopy(t *testing.T) { |
| if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| - if err := os.WriteFile(path, []byte("#!/bin/sh\n# v1\n"), 0o755); err != nil { |
| + if err := writeExecutable(path, []byte("#!/bin/sh\n# v1\n"), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| sum, err := release.FileSHA256(path) |
diff --git a/internal/activator/instancekey_test.go b/internal/activator/instancekey_test.go| index 7c9301a64..3f9d64f0e 100644 |
| --- a/internal/activator/instancekey_test.go |
| +++ b/internal/activator/instancekey_test.go |
| @@ -809,7 +809,7 @@ func TestExecBackendSeedMintsTheKeyForAFreshFlatInstance(t *testing.T) { |
| t.Fatalf("Seed: %v", err) |
| } |
| seed := map[string]string{} |
| - for _, line := range strings.Split(waitForFile(t, envPath, time.Second), "\n") { |
| + for _, line := range strings.Split(waitForFileContent(t, envPath, time.Second), "\n") { |
| if k, v, ok := strings.Cut(line, "="); ok { |
| seed[k] = v |
| } |
diff --git a/internal/activator/replica_instancekey_test.go b/internal/activator/replica_instancekey_test.go| index 0e15f8b18..ab5c47d86 100644 |
| --- a/internal/activator/replica_instancekey_test.go |
| +++ b/internal/activator/replica_instancekey_test.go |
| @@ -82,7 +82,7 @@ func stageHelperApp(t *testing.T, b *ExecBackend, host, ver string) string { |
| } |
| bin := filepath.Join(vdir, "app") |
| script := fmt.Sprintf("#!/bin/sh\nexec '%s' -test.run='^TestInstanceKeyHelperProcess$'\n", self) |
| - if err := os.WriteFile(bin, []byte(script), 0o755); err != nil { |
| + if err := writeExecutable(bin, []byte(script), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| if err := os.MkdirAll(filepath.Join(b.OptDir, "live"), 0o755); err != nil { |
diff --git a/internal/activator/rolelaunch_root_linux_test.go b/internal/activator/rolelaunch_root_linux_test.go| index 6fdd808bf..e64d4a93a 100644 |
| --- a/internal/activator/rolelaunch_root_linux_test.go |
| +++ b/internal/activator/rolelaunch_root_linux_test.go |
| @@ -92,7 +92,7 @@ func newRootLaunchFixture(t *testing.T) *rootLaunchFixture { |
| t.Fatal(err) |
| } |
| } |
| - if err := os.WriteFile(f.exe, []byte("build"), 0o555); err != nil { |
| + if err := writeExecutable(f.exe, []byte("build"), 0o555); err != nil { |
| t.Fatal(err) |
| } |
| var st unix.Stat_t |
diff --git a/internal/activator/swap_fixture_test.go b/internal/activator/swap_fixture_test.go| index caf99676c..78afa4b3d 100644 |
| --- a/internal/activator/swap_fixture_test.go |
| +++ b/internal/activator/swap_fixture_test.go |
| @@ -301,7 +301,7 @@ func newSwapFixtureOn(t *testing.T, wrap func(*fakeSwapBackend) Backend) *swapFi |
| t.Fatal(err) |
| } |
| f.staged = filepath.Join(dir, "app") |
| - if err := os.WriteFile(f.staged, []byte("build v2"), 0o755); err != nil { |
| + if err := writeExecutable(f.staged, []byte("build v2"), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| sum := sha256.Sum256([]byte("build v2")) |
diff --git a/internal/activator/swap_sidecar_test.go b/internal/activator/swap_sidecar_test.go| index 326f91549..75ff3cdca 100644 |
| --- a/internal/activator/swap_sidecar_test.go |
| +++ b/internal/activator/swap_sidecar_test.go |
| @@ -587,7 +587,7 @@ func TestStartSidecarGenKeepsTheRoleSidecarChild(t *testing.T) { |
| t.Fatal(err) |
| } |
| // It stays up until the stop: its exit removes its own child. |
| - if err := os.WriteFile(v2, []byte("#!/bin/sh\nexec sleep 30\n"), 0o755); err != nil { |
| + if err := writeExecutable(v2, []byte("#!/bin/sh\nexec sleep 30\n"), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| if err := os.WriteFile(filepath.Join(b.DataDir, host+"-sidecar.env"), []byte("X=1\n"), 0o600); err != nil { |
| @@ -627,7 +627,7 @@ func TestExecBackendStartSidecarGen(t *testing.T) { |
| if err := os.MkdirAll(filepath.Dir(v2), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| - if err := os.WriteFile(v2, []byte("#!/bin/sh\nprintf '%s' \"$0\" > '"+marker+"'\n"), 0o755); err != nil { |
| + if err := writeExecutable(v2, []byte("#!/bin/sh\nprintf '%s' \"$0\" > '"+marker+"'\n"), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| if err := os.WriteFile(filepath.Join(b.DataDir, host+"-sidecar.env"), []byte("X=1\n"), 0o600); err != nil { |
| @@ -651,7 +651,7 @@ func TestExecBackendStartSidecarGen(t *testing.T) { |
| t.Fatal(err) |
| } |
| defer p.Stop(context.Background()) //nolint:errcheck |
| - if got := waitForFile(t, marker, 2*time.Second); got != v2 { |
| + if got := waitForFileContent(t, marker, 2*time.Second); got != v2 { |
| t.Fatalf("the sidecar execd %q, want the generation's %q", got, v2) |
| } |
| }) |
| @@ -669,7 +669,7 @@ func TestExecBackendStartSidecarGen(t *testing.T) { |
| t.Fatal(err) |
| } |
| defer p.Stop(context.Background()) //nolint:errcheck |
| - if got := waitForFile(t, marker, 2*time.Second); got != v2 { |
| + if got := waitForFileContent(t, marker, 2*time.Second); got != v2 { |
| t.Fatalf("the sidecar execd %q, want the generation's %q", got, v2) |
| } |
| }) |
diff --git a/internal/activator/swap_sim_test.go b/internal/activator/swap_sim_test.go| index 4362f8540..2f0e3d710 100644 |
| --- a/internal/activator/swap_sim_test.go |
| +++ b/internal/activator/swap_sim_test.go |
| @@ -126,7 +126,7 @@ func stageSimBuilds(t *testing.T) map[string]simArtifact { |
| } |
| p := filepath.Join(dir, "app") |
| body := []byte("build " + b) |
| - if err := os.WriteFile(p, body, 0o755); err != nil { |
| + if err := writeExecutable(p, body, 0o755); err != nil { |
| t.Fatal(err) |
| } |
| sum := sha256.Sum256(body) |
diff --git a/internal/activator/wakeidentity_test.go b/internal/activator/wakeidentity_test.go| index 6c317d1fd..3cc2fe9ae 100644 |
| --- a/internal/activator/wakeidentity_test.go |
| +++ b/internal/activator/wakeidentity_test.go |
| @@ -4,7 +4,6 @@ import ( |
| "context" |
| "errors" |
| "fmt" |
| - "os" |
| "path/filepath" |
| "slices" |
| "strings" |
| @@ -567,7 +566,7 @@ func TestANestedUnversionedLinkWithNoHookWakesAsToday(t *testing.T) { |
| eb, rt := nestedBackend(t, ctl, unit) |
| eb.Control = rootLikeControl{identityControl{ctl}} |
| hand := filepath.Join(t.TempDir(), "app") |
| - if err := os.WriteFile(hand, []byte("#!/bin/sh\n"), 0o755); err != nil { |
| + if err := writeExecutable(hand, []byte("#!/bin/sh\n"), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| repointLiveLink(t, eb, rt.Host, hand) |
diff --git a/internal/activator/wakeplan_test.go b/internal/activator/wakeplan_test.go| index b0c767c4e..ccf333ea7 100644 |
| --- a/internal/activator/wakeplan_test.go |
| +++ b/internal/activator/wakeplan_test.go |
| @@ -134,7 +134,7 @@ func stagedID(t *testing.T, dir, ver string) release.StagedIdentity { |
| t.Helper() |
| body := []byte("build " + ver) |
| path := filepath.Join(dir, ver) |
| - if err := os.WriteFile(path, body, 0o755); err != nil { |
| + if err := writeExecutable(path, body, 0o755); err != nil { |
| t.Fatal(err) |
| } |
| sum := sha256.Sum256(body) |
| @@ -675,7 +675,7 @@ func (b *execStagedBackend) KillGen(ctx context.Context, _ registry.Route, n uin |
| func stagedScript(t *testing.T, dir, ver, body string) release.StagedIdentity { |
| t.Helper() |
| path := filepath.Join(dir, ver) |
| - if err := os.WriteFile(path, []byte(body), 0o755); err != nil { |
| + if err := writeExecutable(path, []byte(body), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| sum := sha256.Sum256([]byte(body)) |
diff --git a/internal/activator/wakerecord_refused_test.go b/internal/activator/wakerecord_refused_test.go| index 2c46a9fad..c94a829d7 100644 |
| --- a/internal/activator/wakerecord_refused_test.go |
| +++ b/internal/activator/wakerecord_refused_test.go |
| @@ -38,7 +38,7 @@ func (b *execIdentityBackend) identityFor(registry.Route) identityBackend { retu |
| func stageScript(t *testing.T, eb *ExecBackend, host, body string) { |
| t.Helper() |
| stageLive(t, eb, host, "v1") |
| - if err := os.WriteFile(filepath.Join(eb.OptDir, "versions", "v1", "app"), []byte(body), 0o755); err != nil { |
| + if err := writeExecutable(filepath.Join(eb.OptDir, "versions", "v1", "app"), []byte(body), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| } |
diff --git a/internal/activator/worker_generations_test.go b/internal/activator/worker_generations_test.go| index 22659f7e2..16b641228 100644 |
| --- a/internal/activator/worker_generations_test.go |
| +++ b/internal/activator/worker_generations_test.go |
| @@ -229,7 +229,7 @@ func TestWorkerCapturedBuildSurvivesARestageOfItsReusedName(t *testing.T) { |
| } |
| // The child's own startup write, waited out so it cannot land after the |
| // removal below and pass for the recycle's. |
| - if got := strings.TrimSpace(waitForFile(t, argv0, 5*time.Second)); got != stagedA { |
| + if got := strings.TrimSpace(waitForFileContent(t, argv0, 5*time.Second)); got != stagedA { |
| t.Fatalf("the wake exec'd %q; want A's staged path %s", got, stagedA) |
| } |
| captured := a.entryServing(host) |
| @@ -297,7 +297,7 @@ func TestWorkerCapturedBuildSurvivesARestageOfItsReusedName(t *testing.T) { |
| t.Fatalf("crash the worker: %v", err) |
| } |
| a.sweepOnce() |
| - if got := strings.TrimSpace(waitForFile(t, argv0, 5*time.Second)); got != stagedA { |
| + if got := strings.TrimSpace(waitForFileContent(t, argv0, 5*time.Second)); got != stagedA { |
| t.Fatalf("the recycle exec'd %q; want A's staged path %s", got, stagedA) |
| } |
| waitFor(t, "the recycle to land", func() bool { |
| @@ -472,7 +472,7 @@ func TestWorkerFromAChainedLinkIsPublishedByPath(t *testing.T) { |
| if err := a.WakeWorker(rt); err != nil { |
| t.Fatalf("WakeWorker: %v", err) |
| } |
| - if got := strings.TrimSpace(waitForFile(t, argv0, 5*time.Second)); got != staged { |
| + if got := strings.TrimSpace(waitForFileContent(t, argv0, 5*time.Second)); got != staged { |
| t.Fatalf("the wake exec'd %q; want %s", got, staged) |
| } |
| if id := a.entryServing(host); id.Version != "" || id.StagedPath != staged { |
diff --git a/internal/activator/worker_staged_test.go b/internal/activator/worker_staged_test.go| index 9939d4243..03dd9b36b 100644 |
| --- a/internal/activator/worker_staged_test.go |
| +++ b/internal/activator/worker_staged_test.go |
| @@ -101,7 +101,7 @@ func stageArgv0Worker(t *testing.T, b *ExecBackend, host, ver, out string) strin |
| } |
| bin := filepath.Join(vdir, "app") |
| script := "#!/bin/sh\n# build " + ver + "\nprintf '%s\\n' \"$0\" > '" + out + ".tmp' && mv '" + out + ".tmp' '" + out + "'\nexec sleep 30\n" |
| - if err := os.WriteFile(bin, []byte(script), 0o755); err != nil { |
| + if err := writeExecutable(bin, []byte(script), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| if err := os.MkdirAll(filepath.Join(b.OptDir, "live"), 0o755); err != nil { |
| @@ -130,7 +130,7 @@ func TestExecBackendWorkerExecsTheStagedPathItResolved(t *testing.T) { |
| t.Fatalf("StartWorkerStaged: %v", err) |
| } |
| defer p.Stop(context.Background()) |
| - if got := strings.TrimSpace(waitForFile(t, out, 5*time.Second)); got != bin { |
| + if got := strings.TrimSpace(waitForFileContent(t, out, 5*time.Second)); got != bin { |
| t.Fatalf("$0 = %q; want the staged path %q, never live/%s", got, bin, host) |
| } |
| sum, err := release.FileSHA256(bin) |
| @@ -165,7 +165,7 @@ func TestExecBackendWorkerRecycleExecsTheCapturedBuildAfterARepoint(t *testing.T |
| t.Fatalf("recycle onto v1: %v", err) |
| } |
| defer p2.Stop(context.Background()) |
| - if got := strings.TrimSpace(waitForFile(t, out1, 5*time.Second)); got != bin1 { |
| + if got := strings.TrimSpace(waitForFileContent(t, out1, 5*time.Second)); got != bin1 { |
| t.Fatalf("recycle exec'd %q, want the captured %q", got, bin1) |
| } |
| if id2 != id1 { |
| @@ -187,7 +187,7 @@ func TestExecBackendWorkerRecycleRefusesAChangedStagedCopy(t *testing.T) { |
| waitForFile(t, out, 5*time.Second) |
| p1.Stop(context.Background()) |
| os.Remove(out) |
| - if err := os.WriteFile(bin, []byte("#!/bin/sh\n# tampered, and longer than the original\nexec sleep 30\n"), 0o755); err != nil { |
| + if err := writeExecutable(bin, []byte("#!/bin/sh\n# tampered, and longer than the original\nexec sleep 30\n"), 0o755); err != nil { |
| t.Fatal(err) |
| } |
| p2, _, err := b.StartWorkerStaged(context.Background(), workerRoute(host), nil, &id1) |
diff --git a/internal/console/claim_invariant_fixtures_test.go b/internal/console/claim_invariant_fixtures_test.go| index d652a234b..785922768 100644 |
| --- a/internal/console/claim_invariant_fixtures_test.go |
| +++ b/internal/console/claim_invariant_fixtures_test.go |
| @@ -442,7 +442,7 @@ func (cx *claimCase) scanObjectStaged(t *testing.T) { |
| if err != nil || rec == nil || rec.Provisioned == nil { |
| t.Fatalf("granted store record %+v %v", rec, err) |
| } |
| - cx.scanFake.PutObject(rec.Provisioned.Bucket, "claim-fixture.txt", `"claim-fixture"`, time.Now().Add(-time.Hour), 3) |
| + cx.scanFake.PutObject(rec.Provisioned.Bucket, "claim-fixture.txt", `"claim-fixture"`, claimFixtureModified, 3) |
| } |
| // scanQueued stages one on-demand item for the drain to read. |
diff --git a/internal/console/claim_invariant_world_test.go b/internal/console/claim_invariant_world_test.go| index 6f3ec9727..e53dc5f6a 100644 |
| --- a/internal/console/claim_invariant_world_test.go |
| +++ b/internal/console/claim_invariant_world_test.go |
| @@ -631,11 +631,20 @@ func claimSafeName(s string) string { |
| // scanner's Scan rather than finishing on an empty bucket. |
| type claimOneObjectLister struct{} |
| +// claimFixtureModified is claim-fixture.txt's last-modified time, fixed: an |
| +// object's version is its ETag and its Modified to the second |
| +// (ScanObject.Version), and the lister and scanObjectStaged each took |
| +// time.Now() an hour back. When a second ticked between the stage and the |
| +// sweep's listing, the sweep recorded its verdict on another version than |
| +// the scanner held, and the scan/object probe read "pending" (CI under |
| +// load, TestClaimConsoleMutationInvariant). |
| +var claimFixtureModified = time.Date(2026, 10, 1, 12, 0, 0, 0, time.UTC) |
| + |
| func (claimOneObjectLister) ListPage(_ context.Context, _, startAfter string, _ int32) ([]objstore.ScanObject, bool, error) { |
| if startAfter != "" { |
| return nil, false, nil |
| } |
| - return []objstore.ScanObject{{Key: "claim-fixture.txt", ETag: `"claim-fixture"`, Size: 3, Modified: time.Now().Add(-time.Hour)}}, false, nil |
| + return []objstore.ScanObject{{Key: "claim-fixture.txt", ETag: `"claim-fixture"`, Size: 3, Modified: claimFixtureModified}}, false, nil |
| } |
| // enroll stages an existing, open incarnation: the console's row bound to |
diff --git a/internal/console/lifetimes_purge_test.go b/internal/console/lifetimes_purge_test.go| index 8fc6a4b81..7fbcd500c 100644 |
| --- a/internal/console/lifetimes_purge_test.go |
| +++ b/internal/console/lifetimes_purge_test.go |
| @@ -234,9 +234,22 @@ func TestConsolePurgeRetiresEveryLifetime(t *testing.T) { |
| l := newLtOn(t) |
| l.pendingCreate(t, ltFresh, "record") |
| second := l.restart(t) |
| - unlock := l.fx.srv.lockApp("bab", ltApp) |
| + // The app lock is in-process, per Server: it is the restarted |
| + // console's that its recovery waits on. Taking the first console's |
| + // held nothing back, so on a loaded runner the recovery could run |
| + // before the trash and commit the allocation (CI 2026-10-26). |
| + var appWaits atomic.Int32 |
| + h := func(kind, key, event string) { |
| + if kind == "app" && key == "bab/"+ltApp && event == lockWaiting { |
| + appWaits.Add(1) |
| + } |
| + } |
| + lifetimeLockHook.Store(&h) |
| + t.Cleanup(func() { lifetimeLockHook.Store(nil) }) |
| + unlock := second.lockApp("bab", ltApp) |
| done := make(chan struct{}) |
| go func() { recoverOn(t, second); close(done) }() |
| + waitCount(t, &appWaits, 2, "the recovery to wait on the app lock") |
| trashShop(t, l) |
| unlock() |
| <-done |
diff --git a/internal/dbreads/fixture_test.go b/internal/dbreads/fixture_test.go| index b6388798e..9f3bc3b6e 100644 |
| --- a/internal/dbreads/fixture_test.go |
| +++ b/internal/dbreads/fixture_test.go |
| @@ -112,6 +112,18 @@ func (w *inProcWorkers) units(context.Context) (int, error) { return int(w.live. |
| func plentyFree() (uint64, uint64, error) { return 100 << 30, 200 << 30, nil } |
| +// waitFor polls cond until it holds, failing the test after ten seconds. |
| +func waitFor(t *testing.T, what string, cond func() bool) { |
| + t.Helper() |
| + deadline := time.Now().Add(10 * time.Second) |
| + for !cond() { |
| + if time.Now().After(deadline) { |
| + t.Fatalf("timed out waiting for %s", what) |
| + } |
| + time.Sleep(time.Millisecond) |
| + } |
| +} |
| + |
| type fixture struct { |
| t *testing.T |
| store release.Store |
diff --git a/internal/dbreads/loop_test.go b/internal/dbreads/loop_test.go| index ea8e7441c..ac825ef47 100644 |
| --- a/internal/dbreads/loop_test.go |
| +++ b/internal/dbreads/loop_test.go |
| @@ -159,12 +159,18 @@ func TestADrainingBoxDoesNotPick(t *testing.T) { |
| c.Draining = flip.Load |
| c.Jitter = func() time.Duration { flip.Store(true); return time.Millisecond } |
| }) |
| - healthy, _ := fx.agent("uk-1") |
| + healthy, hw := fx.agent("uk-1") |
| for i := 0; i < 5; i++ { |
| req := fx.request("SELECT 1", "") |
| fx.submit(req) |
| drain.Pass(context.Background()) // first: it passes the first check, then drains in its jitter |
| drain.Wait() |
| + // The last read's worker unit goes away after its connection does, |
| + // as systemd's deactivation does: a pass before then counts it as an |
| + // orphan and admits nothing, and this test makes one pass a read |
| + // (CI 2026-10-26, "no result for dbr_..."). Production passes again |
| + // on its ticker; here, wait for the unit to go. |
| + waitFor(t, "the last worker unit to go", func() bool { return hw.live.Load() == 0 }) |
| healthy.Pass(context.Background()) |
| healthy.Wait() |
| if _, _, r := fx.answer(req.ID); r.Box != "uk-1" { |
diff --git a/internal/dbreads/read_test.go b/internal/dbreads/read_test.go| index ad0bd5d50..e6c7b8b60 100644 |
| --- a/internal/dbreads/read_test.go |
| +++ b/internal/dbreads/read_test.go |
| @@ -528,13 +528,23 @@ func (s slowPicked) Put(ctx context.Context, key string, body []byte, ifMatch st |
| // one from whenever the election's answer arrived (Astra round 1, finding |
| // 3): a hung read ends by picked.Deadline, and a read whose election |
| // answered after its deadline starts no work at all. |
| +// |
| +// The margins are wide enough for a loaded runner (CI 2026-10-25 and |
| +// 2026-10-27: a 600 ms deadline passed before the dial, and an answer 100 ms |
| +// late plus scheduling ran past a 150 ms allowance) and still tell the bug |
| +// apart: a deadline taken afresh when the election answered would end the |
| +// first case a whole delay (1 s) late, over twice the allowance. |
| func TestServeKeepsThePublishedDeadline(t *testing.T) { |
| t.Parallel() |
| + // slack is how long after the later of the published deadline and the |
| + // election's answer the read may end: the result's own write and the |
| + // scheduler. |
| + const slack = 500 * time.Millisecond |
| for name, c := range map[string]struct { |
| deadline, delay time.Duration |
| dials int64 |
| }{ |
| - "a late answer inside the deadline": {deadline: 600 * time.Millisecond, delay: 300 * time.Millisecond, dials: 1}, |
| + "a late answer inside the deadline": {deadline: 2500 * time.Millisecond, delay: time.Second, dials: 1}, |
| "an answer after the deadline": {deadline: 200 * time.Millisecond, delay: 300 * time.Millisecond, dials: 0}, |
| } { |
| t.Run(name, func(t *testing.T) { |
| @@ -561,7 +571,9 @@ func TestServeKeepsThePublishedDeadline(t *testing.T) { |
| if r.State != StateFailed || r.Code != CodeInterrupted || w.dials.Load() != c.dials { |
| t.Fatalf("result %+v, %d worker connections", r, w.dials.Load()) |
| } |
| - if over := r.Ended.Sub(p.Deadline); over > 150*time.Millisecond { |
| + // An answer after the deadline cannot end the read before it |
| + // arrives: that much past the deadline is allowed too. |
| + if over := r.Ended.Sub(p.Deadline); over > slack+max(0, c.delay-c.deadline) { |
| t.Fatalf("the read ran %s past the deadline it published", over) |
| } |
| }) |
diff --git a/internal/host/applylock_linux_test.go b/internal/host/applylock_linux_test.go| new file mode 100644 |
| index 000000000..b5fcd9e4e |
| --- /dev/null |
| +++ b/internal/host/applylock_linux_test.go |
| @@ -0,0 +1,49 @@ |
| +//go:build linux |
| + |
| +package host |
| + |
| +import ( |
| + "errors" |
| + "os" |
| + "syscall" |
| + "testing" |
| + "time" |
| +) |
| + |
| +// awaitApplyLockFree waits until nothing holds a's apply lock any more. |
| +// |
| +// An apply closes its lock when it returns, but a parallel test that forked |
| +// while the lock was open has a copy of that descriptor in its child until |
| +// the child execs, and the flock stays held through the copy. On a loaded |
| +// runner that lasts long enough for the next locker in this test to be |
| +// refused: "an update is running on this box ... resource temporarily |
| +// unavailable" (TestInstallChannelPolicyRefusals, CI 2026-10-26 and |
| +// 2026-10-27). The probe unlocks explicitly before closing, so a fork that |
| +// copies its own descriptor cannot hold the lock in turn. |
| +func awaitApplyLockFree(t *testing.T, a *systemApplier) { |
| + t.Helper() |
| + deadline := time.Now().Add(10 * time.Second) |
| + for { |
| + f, err := os.OpenFile(a.lockPath(), os.O_RDWR, 0) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + err = syscall.Flock(int(f.Fd()), syscall.LOCK_EX|syscall.LOCK_NB) |
| + if err == nil { |
| + err = syscall.Flock(int(f.Fd()), syscall.LOCK_UN) |
| + f.Close() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return |
| + } |
| + f.Close() |
| + if !errors.Is(err, syscall.EWOULDBLOCK) { |
| + t.Fatal(err) |
| + } |
| + if time.Now().After(deadline) { |
| + t.Fatalf("the apply lock %s is still held 10s after the apply returned", a.lockPath()) |
| + } |
| + time.Sleep(time.Millisecond) |
| + } |
| +} |
diff --git a/internal/host/applylock_other_test.go b/internal/host/applylock_other_test.go| new file mode 100644 |
| index 000000000..6c9f6d283 |
| --- /dev/null |
| +++ b/internal/host/applylock_other_test.go |
| @@ -0,0 +1,9 @@ |
| +//go:build !linux |
| + |
| +package host |
| + |
| +import "testing" |
| + |
| +// awaitApplyLockFree has nothing to wait for where the apply lock is not |
| +// supported (flockExclusiveNonblock is errSystemUnsupported). |
| +func awaitApplyLockFree(*testing.T, *systemApplier) {} |
diff --git a/internal/host/caps_pass_test.go b/internal/host/caps_pass_test.go| index f530fc66a..73f7787df 100644 |
| --- a/internal/host/caps_pass_test.go |
| +++ b/internal/host/caps_pass_test.go |
| @@ -8,6 +8,7 @@ import ( |
| "os" |
| "path/filepath" |
| "strings" |
| + "sync" |
| "testing" |
| "github.com/carlosframework/platform/internal/caps" |
| @@ -855,3 +856,45 @@ func TestCapabilityPassStampsDBPathEvenWhenConvergeIsRefused(t *testing.T) { |
| t.Errorf("DBPath = %q, want %q — a capability refusal is not a reason to stop replicating data", got.DBPath, want) |
| } |
| } |
| + |
| +// captureLogThen is captureLog that also calls fn, once, when a line |
| +// containing marker is logged, before the logging call returns: a test |
| +// can act at the moment the code under test announces a step. |
| +func captureLogThen(t *testing.T, marker string, fn func()) func() string { |
| + t.Helper() |
| + w := &markerWriter{marker: marker, fn: fn} |
| + old := log.Writer() |
| + flags := log.Flags() |
| + log.SetOutput(w) |
| + log.SetFlags(0) |
| + t.Cleanup(func() { log.SetOutput(old); log.SetFlags(flags) }) |
| + return w.String |
| +} |
| + |
| +type markerWriter struct { |
| + mu sync.Mutex |
| + buf bytes.Buffer |
| + marker string |
| + fn func() |
| + fired bool |
| +} |
| + |
| +func (w *markerWriter) Write(p []byte) (int, error) { |
| + w.mu.Lock() |
| + n, err := w.buf.Write(p) |
| + fire := !w.fired && bytes.Contains(p, []byte(w.marker)) |
| + if fire { |
| + w.fired = true |
| + } |
| + w.mu.Unlock() |
| + if fire { |
| + w.fn() |
| + } |
| + return n, err |
| +} |
| + |
| +func (w *markerWriter) String() string { |
| + w.mu.Lock() |
| + defer w.mu.Unlock() |
| + return w.buf.String() |
| +} |
diff --git a/internal/host/installchannel_policy_test.go b/internal/host/installchannel_policy_test.go| index db8f0f92f..02d65f9a4 100644 |
| --- a/internal/host/installchannel_policy_test.go |
| +++ b/internal/host/installchannel_policy_test.go |
| @@ -99,6 +99,7 @@ func applyChannelUpdateWith(t *testing.T, f *channelFixture, version string, bod |
| if err := f.a.Run(ctx, false); err != nil { |
| t.Fatal(err) |
| } |
| + awaitApplyLockFree(t, f.a) |
| if r := f.result(); r == nil || r.Outcome != systemOutcomeApplied || r.Version != version { |
| t.Fatalf("the update to %s did not apply: %+v", version, r) |
| } |
diff --git a/internal/host/movesoffline_stage_test.go b/internal/host/movesoffline_stage_test.go| index 047efc554..649e72854 100644 |
| --- a/internal/host/movesoffline_stage_test.go |
| +++ b/internal/host/movesoffline_stage_test.go |
| @@ -237,7 +237,8 @@ func TestOfflineStageThenStartThenSealSkipsThePreCopy(t *testing.T) { |
| // object the stage copied is still in the replica, unchanged, and the |
| // seal copied none of those (the loop below). |
| kept := 0 |
| - for rel, o := range sw.replicaRel() { |
| + atSeal := sw.replicaRel() |
| + for rel, o := range atSeal { |
| if s, ok := preStaged[rel]; ok && s.Size == o.Size && preReplica[rel].ETag == o.ETag { |
| kept++ |
| } |
| @@ -246,11 +247,18 @@ func TestOfflineStageThenStartThenSealSkipsThePreCopy(t *testing.T) { |
| t.Fatal("fixture: no pre-copied object survived to the seal, so nothing shows a skip") |
| } |
| t.Logf("the seal copied %d of %d objects; %d were pre-copied and skipped", len(sealCopies), len(sw.replicaRel()), kept) |
| + // A recopy is wrong only for an object the replica still holds as the |
| + // stage copied it. Litestream rewrites a snapshot under the same key |
| + // (0009/<range>.ltx, same size, a new header timestamp) when its |
| + // compaction runs again, and then the seal must copy it: comparing |
| + // against the replica as it was at the stage alone failed whenever that |
| + // rewrite landed in between (here at -cpu 4 without load, 3 of 9). |
| for _, k := range sealCopies { |
| rel := strings.TrimPrefix(k, sealPrefix+"/"+offHost+"/") |
| s, staged := preStaged[rel] |
| o, listed := preReplica[rel] |
| - if staged && listed && s.Size == o.Size && s.ETag == o.ETag { |
| + now, still := atSeal[rel] |
| + if staged && listed && still && s.Size == o.Size && s.ETag == o.ETag && now.ETag == o.ETag && now.Size == o.Size { |
| t.Fatalf("the seal recopied %s, which the stage had copied", rel) |
| } |
| } |
diff --git a/internal/host/movesphase1_test.go b/internal/host/movesphase1_test.go| index a5559b936..4d6d03cec 100644 |
| --- a/internal/host/movesphase1_test.go |
| +++ b/internal/host/movesphase1_test.go |
| @@ -428,27 +428,52 @@ func TestPreparingTouchesTheTargetRegionAndBoxFirst(t *testing.T) { |
| // A failed copy is retried only by calling again: the lane asks the guard |
| // again before the retry, and a lease past the bound by then ends the round |
| // with no second request. |
| +// |
| +// A round's copies run side by side (lease.MirrorPrefixKeep), so the test |
| +// pins nothing to their order. The lease is cut short when the lane |
| +// announces its retry, after every copy of the first round has returned: |
| +// cutting it from inside the failing copy raced the sibling copy, which |
| +// could pass its guard first (a second request, CI 2026-10-27) or be |
| +// refused first (the round ending on the refusal with no retry). And the |
| +// retry is told apart per object: only the object whose copy failed is |
| +// sure to be copied again. |
| func TestStagingWriterRetriesWithANewCheck(t *testing.T) { |
| h := newPhase1Harness(t) |
| h.start(t, "manual") |
| // The first copy fails, and by its retry the lease is too close to |
| - // its end. |
| - copies := 0 |
| + // its end. failAt runs under the fake's lock, and so does the |
| + // announcement's read of failedKey. |
| + copied := map[string]int{} |
| + failedKey, announced, afterRetry := "", false, 0 |
| h.f.failAt = func(op, key string) error { |
| if op != "copy" { |
| return nil |
| } |
| - copies++ |
| - if copies == 1 { |
| - h.lease.until = h.clock.now.Add(time.Minute) |
| + copied[key]++ |
| + if announced { |
| + afterRetry++ |
| + } |
| + if failedKey == "" { |
| + failedKey = key |
| return errors.New("injected 503") |
| } |
| return nil |
| } |
| - logs := captureLog(t) |
| + logs := captureLogThen(t, "retrying once", func() { |
| + h.f.mu.Lock() |
| + announced = true |
| + h.f.mu.Unlock() |
| + safe := h.clock.Now().Add(time.Minute) |
| + h.lease.mu.Lock() |
| + h.lease.until = safe |
| + h.lease.mu.Unlock() |
| + }) |
| h.pass(t) |
| - if copies != 1 { |
| - t.Fatalf("%d copy requests reached the store, want 1", copies) |
| + if failedKey == "" { |
| + t.Fatal("no copy request reached the store") |
| + } |
| + if copied[failedKey] != 1 || afterRetry != 0 { |
| + t.Fatalf("the failed object was requested %d times, %d requests after the retry was announced; want 1 and 0 (%v)", copied[failedKey], afterRetry, copied) |
| } |
| if !strings.Contains(logs(), "retrying once") || !strings.Contains(logs(), moves.ErrLeaseUnsafe.Error()) { |
| t.Fatalf("the retry did not go back to the guard:\n%s", logs()) |
| @@ -457,23 +482,23 @@ func TestStagingWriterRetriesWithANewCheck(t *testing.T) { |
| // With the lease safe, the retry's request is signed at a new check. |
| h2 := newPhase1Harness(t) |
| h2.start(t, "manual") |
| - var signs []time.Time |
| - failed := false |
| + var failedAt string |
| + signs := map[string][]time.Time{} |
| h2.f.failAt = func(op, key string) error { |
| if op != "copy" { |
| return nil |
| } |
| calls := h2.f.at |
| - signs = append(signs, calls[len(calls)-1].SignAt) |
| - if !failed { |
| - failed = true |
| + signs[key] = append(signs[key], calls[len(calls)-1].SignAt) |
| + if failedAt == "" { |
| + failedAt = key |
| return errors.New("injected 503") |
| } |
| return nil |
| } |
| h2.pass(t) |
| - if len(signs) < 2 || !signs[1].After(signs[0]) { |
| - t.Fatalf("the retry reused the first signature time: %v", signs) |
| + if s := signs[failedAt]; len(s) < 2 || !s[1].After(s[0]) { |
| + t.Fatalf("the retry of %s reused the first signature time: %v", failedAt, s) |
| } |
| } |
diff --git a/internal/rollout/fake_test.go b/internal/rollout/fake_test.go| index fa5528d89..0bbbc486a 100644 |
| --- a/internal/rollout/fake_test.go |
| +++ b/internal/rollout/fake_test.go |
| @@ -530,6 +530,15 @@ func (h *harness) flushAcks() { |
| waitFor(h.t, "the ack writer to finish", h.m.acks.idle) |
| } |
| +// pointerReadIsDue reports whether the next pass reads k's pointers whatever |
| +// the clock says (pointerReadDue has run since the last read). |
| +func (m *Manager) pointerReadIsDue(k appKey) bool { |
| + m.mu.Lock() |
| + defer m.mu.Unlock() |
| + _, read := m.pointerRead[k] |
| + return !read |
| +} |
| + |
| func waitFor(t *testing.T, what string, cond func() bool) { |
| t.Helper() |
| deadline := time.Now().Add(5 * time.Second) |
diff --git a/internal/rollout/holdran_test.go b/internal/rollout/holdran_test.go| index 2eb2aa930..1558fff88 100644 |
| --- a/internal/rollout/holdran_test.go |
| +++ b/internal/rollout/holdran_test.go |
| @@ -616,7 +616,13 @@ func TestAnInstallOntoTheGoodBuildMakesTheRollbackReadDueAtOnce(t *testing.T) { |
| h.pass() // the newer desire supersedes the attempt |
| h.advance(5 * time.Second) |
| close(gate) |
| - waitFor(t, "h's attempt to finish", func() bool { return !h.m.attemptRunning("h") }) |
| + // The attempt's done() frees the slot and sets the marker, then |
| + // makes the read due once it has let go of the scheduler's lock: |
| + // a pass in between does not read (CI 2026-10-27, "after the pass |
| + // the marker stands"). So the wait is for both. |
| + waitFor(t, "h's attempt to finish and make the pointer read due", func() bool { |
| + return !h.m.attemptRunning("h") && h.m.pointerReadIsDue(appKey{"bab", "blog"}) |
| + }) |
| got, ok := h.book.HoldRanOn("h") |
| if !ok || !got.same(markV2) || !got.At.Equal(start) { |
| t.Fatalf("marker = %+v, %v: want v2's, stamped at the attempt's dispatch %v", got, ok, start) |
| @@ -787,12 +793,35 @@ func TestAMoveOntoTheInstalledGoodBuildWaitsForASignedRollback(t *testing.T) { |
| // `carlos rollback` signs v1; the pointer pass clears the marker, |
| // and the next derivation moves h onto v1. |
| + // |
| + // The second gated attempt's done() pokes the scheduler after its |
| + // slot is free, so a derivation can run at any moment from here. |
| + // The clock goes first to the pointer read's due time, which is |
| + // still inside the host's abandon deferral: a derivation then |
| + // admits nothing, and the pass clears the marker. Only then does |
| + // the clock leave the deferral. Advancing straight past both let |
| + // that derivation run between the advance and the pass, be gated |
| + // a third time and defer the host for another abandonDeferral |
| + // (CI 2026-10-26, "timed out waiting for the move onto v1"). |
| + // pointer() is signed at the gated attempt's time, so it is newer |
| + // than the marker either way. |
| + // Times from the first pass, which read the pointers; the second |
| + // gated attempt deferred h until abandonDeferral after it ran. |
| + deferredUntil := abandonDeferral + time.Second + abandonDeferral |
| + if pointerReadEvery >= deferredUntil { |
| + t.Fatalf("pointerReadEvery %s no longer falls inside the deferral ending at %s; re-derive this timeline", pointerReadEvery, deferredUntil) |
| + } |
| h.pointer("stable", "v1", h.clock()) |
| - h.advance(pointerReadEvery) |
| + h.advance(pointerReadEvery - (abandonDeferral + time.Second)) |
| h.pass() |
| if got, ok := h.book.HoldRanOn("h"); ok { |
| t.Fatalf("marker %+v survived the signed rollback", got) |
| } |
| + if n := moves(); n != 0 || gatedTimes() != 2 { |
| + t.Fatalf("%d moves and %d gated attempts inside the deferral, want 0 and 2", n, gatedTimes()) |
| + } |
| + h.advance(deferredUntil - pointerReadEvery + time.Second) |
| + h.pass() |
| waitFor(t, "the move onto v1", func() bool { return moves() == 1 }) |
| if calls, _, _ := h.act.snapshot(); len(calls) == 1 && (worker || calls[0].a.Build != "v1") { |
| t.Fatalf("swap %+v: want one onto v1 (and none for a worker)", calls[0].a) |