carlos / platform Public

activator tests: the strict-spawn tests wait for the recorder, not timeouts

The three strict-group tests started a recorder that never binds and sat
out the shrunk 300 ms health wait at every start, and slept 100-200 ms to
show that a refused spawn ran nothing. They now end the health wait once
the recorder has written its argv and exited (recordedCtx), and look for
"nothing ran" until no child of the test binary is left to write it
(awaitChildFile), with the old sleeps as the bound. The 400/500 ms
cleanup backoffs they observe are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev d82e500fc64db20a3e9f2966c91d6270b825d1d8 parent 80755cb
1 file changed, +13 −11
  • internal/activator/backend_exec_test.go +13 −11
diff --git a/internal/activator/backend_exec_test.go b/internal/activator/backend_exec_test.go
index d5fa6a12b..6367658aa 100644
--- a/internal/activator/backend_exec_test.go
+++ b/internal/activator/backend_exec_test.go
@@ -496,10 +496,12 @@ func TestSpawnUnderAMoveIsStrictOrRefused(t *testing.T) {
spawnHealthTimeout = 300 * time.Millisecond
t.Cleanup(func() { spawnHealthTimeout = old })
host := "strict.example.com"
- start := func(t *testing.T, b *ExecBackend) error {
+ // argvPath is the recorder's first file: once it exists and the child
+ // has exited, the health wait the recorder never answers is over.
+ start := func(t *testing.T, b *ExecBackend, argvPath string) error {
t.Helper()
rt := registry.Route{Host: host, Kind: "instance", Socket: filepath.Join(t.TempDir(), "i.sock")}
- ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
+ ctx, cancel := recordedCtx(2*time.Second, argvPath)
defer cancel()
proc, _, err := b.Start(ctx, rt) // the fake binary never binds: a health error is expected
if proc != nil {
@@ -509,7 +511,7 @@ func TestSpawnUnderAMoveIsStrictOrRefused(t *testing.T) {
}
noSpawn := func(t *testing.T, argvPath string) {
t.Helper()
- time.Sleep(200 * time.Millisecond)
+ awaitChildFile(argvPath, 200*time.Millisecond) // until no child is left to write it
if _, err := os.Stat(argvPath); !os.IsNotExist(err) {
t.Fatalf("the child ran: %v", err)
}
@@ -520,7 +522,7 @@ func TestSpawnUnderAMoveIsStrictOrRefused(t *testing.T) {
argvPath, _ := stageRecordingLive(t, b, host, "v1")
b.Strict = func(h string) bool { return h == host }
b.prepareStrict = func(string, cgroup.Limit) (strictProc, error) { return nil, cgroup.ErrStrictRefused }
- if err := start(t, b); !errors.Is(err, ErrStrictRequired) {
+ if err := start(t, b, argvPath); !errors.Is(err, ErrStrictRequired) {
t.Fatalf("Start: %v, want ErrStrictRequired", err)
}
noSpawn(t, argvPath)
@@ -530,7 +532,7 @@ func TestSpawnUnderAMoveIsStrictOrRefused(t *testing.T) {
b := testExecBackend(t) // Cgroups nil
argvPath, _ := stageRecordingLive(t, b, host, "v1")
b.Strict = func(string) bool { return true }
- if err := start(t, b); !errors.Is(err, ErrStrictRequired) {
+ if err := start(t, b, argvPath); !errors.Is(err, ErrStrictRequired) {
t.Fatalf("Start: %v, want ErrStrictRequired", err)
}
noSpawn(t, argvPath)
@@ -543,7 +545,7 @@ func TestSpawnUnderAMoveIsStrictOrRefused(t *testing.T) {
rec := newRecordingStrict()
failing := &failingStrict{recordingStrict: rec}
b.prepareStrict = func(string, cgroup.Limit) (strictProc, error) { return failing, nil }
- if err := start(t, b); !errors.Is(err, ErrStrictRequired) {
+ if err := start(t, b, argvPath); !errors.Is(err, ErrStrictRequired) {
t.Fatalf("Start: %v, want ErrStrictRequired", err)
}
noSpawn(t, argvPath)
@@ -561,7 +563,7 @@ func TestSpawnUnderAMoveIsStrictOrRefused(t *testing.T) {
var gotLimit cgroup.Limit
b.Tier = func(registry.Route) cgroup.Limit { return cgroup.TierChildren }
b.prepareStrict = func(h string, l cgroup.Limit) (strictProc, error) { gotHost, gotLimit = h, l; return rec, nil }
- _ = start(t, b)
+ _ = start(t, b, argvPath)
waitForFile(t, argvPath, time.Second)
select {
case <-rec.closed:
@@ -592,7 +594,7 @@ func TestSpawnUnderAMoveIsStrictOrRefused(t *testing.T) {
asked = true
return nil, errors.New("must not be asked")
}
- _ = start(t, b)
+ _ = start(t, b, argvPath)
waitForFile(t, argvPath, time.Second)
if asked {
t.Fatal("the strict seam was asked for a host not in a move")
@@ -744,7 +746,7 @@ func TestStrictCleanupIsRetriedAndRefusesUntilItSucceeds(t *testing.T) {
prepared := func() int { mu.Lock(); defer mu.Unlock(); return len(handles) }
startOnce := func() error {
rt := registry.Route{Host: host, Kind: "instance", Socket: filepath.Join(t.TempDir(), "i.sock")}
- ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
+ ctx, cancel := recordedCtx(2*time.Second, argvPath) // the recorder ran and exited
defer cancel()
proc, _, err := b.Start(ctx, rt)
if proc != nil {
@@ -948,7 +950,7 @@ func TestPendingStrictCleanupOwnsTheGroup(t *testing.T) {
}
startOnce := func() error {
rt := registry.Route{Host: host, Kind: "instance", Socket: filepath.Join(t.TempDir(), "i.sock")}
- ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
+ ctx, cancel := recordedCtx(2*time.Second, argvPath) // the recorder ran and exited
defer cancel()
proc, _, err := b.Start(ctx, rt)
if proc != nil {
@@ -981,7 +983,7 @@ func TestPendingStrictCleanupOwnsTheGroup(t *testing.T) {
if err := startOnce(); !errors.Is(err, ErrStrictCleanupPending) {
t.Fatalf("ordinary spawn during pending cleanup: %v, want ErrStrictCleanupPending", err)
}
- time.Sleep(100 * time.Millisecond)
+ awaitChildFile(argvPath, 100*time.Millisecond) // until no child is left to write it
if _, err := os.Stat(argvPath); !os.IsNotExist(err) {
t.Fatalf("an ordinary child ran in a group awaiting cleanup: %v", err)
}