carlos / platform Public

sizes: the byte-identical proof observes both wakes' spawn tier (Task 12 review)

A wake-tier-recording backend records ExecBackend's own tier for the
route the Service passes to Start; the seams are set before the first
wake, and both wakes are checked against the Tier seam for TierDefault
and TierChildren.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev d9b56b53c7dda61fc1c57f62da8c94bf7e6a9b71 parent 1301790
1 file changed, +110 −49
  • internal/activator/size_identical_test.go +110 −49
diff --git a/internal/activator/size_identical_test.go b/internal/activator/size_identical_test.go
index 6ec3600b3..cd4a2629b 100644
--- a/internal/activator/size_identical_test.go
+++ b/internal/activator/size_identical_test.go
@@ -10,6 +10,7 @@ import (
"slices"
"sort"
"strings"
+ "sync"
"testing"
"time"
@@ -93,55 +94,115 @@ func TestNoSizeColumnSendsNoLiveCall(t *testing.T) {
}
}
})
- t.Run("a wake, a swap and ten sweeps", func(t *testing.T) {
- t.Parallel()
- // The fixture's host is woken (arrangeAwake) and its route, in the
- // entry and in the local registry, has no size.
- f := newSizeFixture(t, "", 0)
- f.b.tiers = map[string]cgroup.Limit{"v1": cgroup.TierChildren, "v2": cgroup.TierDefault}
- sweeps := 0
- sweep := func() { t.Helper(); f.sweep(t); sweeps++ }
- sweep()
- sweep()
- f.a.NoteSize(f.host) // an egress-only policy converge
- sweep()
- res := f.a.Swap(context.Background(), f.attempt(ModeOverlap), f.newest)
- if res.Outcome != SwapDone {
- t.Fatalf("Swap = %+v", res)
- }
- f.routes.mu.Lock()
- rt := f.routes.rows[f.host]
- f.routes.mu.Unlock()
- seam := f.b.GenTier(rt, "v2")
- if g, _ := f.b.lastGen(); res.Gen.Tier != seam || g.Tier != seam || seam.MemoryMax != 536870912 {
- t.Fatalf("successor: result tier %+v, spawned at %+v; want the seam's %+v (main: 536870912)", res.Gen.Tier, g.Tier, seam)
- }
- sweep()
- f.clk.advance(sizeBackstop)
- sweep()
- f.a.NoteSize(f.host)
- sweep()
- // The host sleeps on its idle timeout and wakes again.
- f.clk.advance(2 * time.Hour)
- f.a.sweepOnce()
- sweeps++
- waitFor(t, "the host asleep", func() bool { return f.a.entryCount() == 0 })
- arrangeAwake(t, f.a, rt)
- if got := f.b.lastStartedRoute(); got.Size != "" {
- t.Fatalf("the wake spawned a route with size %q", got.Size)
- }
- sweep()
- f.clk.advance(sizeBackstop)
- sweep()
- f.a.NoteSize(f.host)
- sweep()
- if sweeps != 10 {
- t.Fatalf("ran %d sweeps, want 10", sweeps)
- }
- if ev := f.sizeEvents(); len(ev) != 0 {
- t.Fatalf("size calls %v with no size column", ev)
- }
- })
+ for _, c := range []struct {
+ name string
+ live, succ cgroup.Limit
+ liveMain, succMain int64 // main's figures (953b9fda)
+ }{
+ {"live TierDefault", cgroup.TierDefault, cgroup.TierChildren, 536870912, 1073741824},
+ {"live TierChildren", cgroup.TierChildren, cgroup.TierDefault, 1073741824, 536870912},
+ } {
+ t.Run("a wake, a swap and ten sweeps, "+c.name, func(t *testing.T) {
+ t.Parallel()
+ // The tier seams are set before the fixture's first wake: the
+ // running build v1 is the live tier, the release v2 the
+ // successor's. Each wake's spawn tier is what ExecBackend
+ // computes from the route the Service hands it (wakeTierBackend).
+ var wb *wakeTierBackend
+ sf := newSwapFixtureOn(t, func(b *fakeSwapBackend) Backend {
+ b.tiers = map[string]cgroup.Limit{"v1": c.live, "v2": c.succ}
+ wb = &wakeTierBackend{fakeSwapBackend: b, eb: &ExecBackend{
+ Tier: func(registry.Route) cgroup.Limit { return c.live },
+ TierOf: func(_ registry.Route, build string) cgroup.Limit { return b.tiers[build] },
+ }}
+ return wb
+ })
+ f := sizeFixtureOf(sf)
+ sweeps := 0
+ sweep := func() { t.Helper(); f.sweep(t); sweeps++ }
+ sweep()
+ sweep()
+ f.a.NoteSize(f.host) // an egress-only policy converge
+ sweep()
+ res := f.a.Swap(context.Background(), f.attempt(ModeOverlap), f.newest)
+ if res.Outcome != SwapDone {
+ t.Fatalf("Swap = %+v", res)
+ }
+ f.routes.mu.Lock()
+ rt := f.routes.rows[f.host]
+ f.routes.mu.Unlock()
+ if g, _ := f.b.lastGen(); res.Gen.Tier != c.succ || g.Tier != c.succ || g.Tier.MemoryMax != c.succMain {
+ t.Fatalf("successor: result tier %+v, spawned at %+v; want TierOf's %+v (main: %d)", res.Gen.Tier, g.Tier, c.succ, c.succMain)
+ }
+ sweep()
+ f.clk.advance(sizeBackstop)
+ sweep()
+ f.a.NoteSize(f.host)
+ sweep()
+ // The host sleeps on its idle timeout and wakes again.
+ f.clk.advance(2 * time.Hour)
+ f.a.sweepOnce()
+ sweeps++
+ waitFor(t, "the host asleep", func() bool { return f.a.entryCount() == 0 })
+ arrangeAwake(t, f.a, rt)
+ sweep()
+ f.clk.advance(sizeBackstop)
+ sweep()
+ f.a.NoteSize(f.host)
+ sweep()
+ if sweeps != 10 {
+ t.Fatalf("ran %d sweeps, want 10", sweeps)
+ }
+ if ev := f.sizeEvents(); len(ev) != 0 {
+ t.Fatalf("size calls %v with no size column", ev)
+ }
+ // Both wakes spawned at the Tier seam's tier, main's figure.
+ wakes := wb.wakeTiers()
+ if len(wakes) != 2 {
+ t.Fatalf("%d wakes spawned, want 2 (the fixture's and the re-wake)", len(wakes))
+ }
+ for i, got := range wakes {
+ if got != c.live || got.MemoryMax != c.liveMain {
+ t.Errorf("wake %d spawned at %+v; want the Tier seam's %+v (main: %d)", i+1, got, c.live, c.liveMain)
+ }
+ }
+ })
+ }
+}
+
+// wakeTierBackend is the swap fake whose wake (Start) records the tier
+// ExecBackend would spawn the route at: eb.tier(rt), ExecBackend's own
+// computation (the size column over the Tier seam), on the very route the
+// Service passes to Start.
+type wakeTierBackend struct {
+ *fakeSwapBackend
+ eb *ExecBackend
+ mu sync.Mutex
+ wakes []cgroup.Limit
+}
+
+func (b *wakeTierBackend) Start(ctx context.Context, rt registry.Route) (Proc, string, error) {
+ b.mu.Lock()
+ b.wakes = append(b.wakes, b.eb.tier(rt))
+ b.mu.Unlock()
+ return b.fakeSwapBackend.Start(ctx, rt)
+}
+
+func (b *wakeTierBackend) wakeTiers() []cgroup.Limit {
+ b.mu.Lock()
+ defer b.mu.Unlock()
+ return slices.Clone(b.wakes)
+}
+
+// sizeFixtureOf is newSizeFixture(t, "", 0) on an existing swap fixture:
+// the local registry holds the entry's route, with no size.
+func sizeFixtureOf(f *swapFixture) *sizeFixture {
+ f.a.mu.Lock()
+ rt := f.a.entries[f.host].route
+ f.a.mu.Unlock()
+ routes := &liveRoutes{rows: map[string]registry.Route{f.host: rt}}
+ f.a.Routes = routes
+ return &sizeFixture{swapFixture: f, routes: routes}
}
// spawnCgroupFiles spawns /bin/true through spawnInCgroup at tier, on a