| index d95a8de93..bd9070654 100644 |
| --- a/internal/activator/swap_overlap_test.go |
| +++ b/internal/activator/swap_overlap_test.go |
| @@ -99,6 +99,74 @@ func TestSwapOverlapUsesEachArtifactsTier(t *testing.T) { |
| }) |
| } |
| |
| +// With an operator size, now or in force at the incumbent's start, the |
| +// successor starts at the larger of its own effective size and the |
| +// incumbent's captured tier, so the restore never lowers memory (spec §5.4 |
| +// rev 8). With no operator size each artifact keeps its own tier, as on |
| +// main: case (c) is TestSwapOverlapUsesEachArtifactsTier/switched. |
| +func TestSwapSuccessorStartsAtTheLargerSizeOnlyWithAnOperatorSize(t *testing.T) { |
| + t.Parallel() |
| + const half, gib, two = int64(1 << 29), int64(1 << 30), int64(2 << 30) |
| + for _, tc := range []struct { |
| + name string |
| + size string // the route's size column at the swap |
| + tiers map[string]cgroup.Limit // each build's own tier |
| + inc int64 // the incumbent's captured tier; 0 = not captured |
| + succ int64 // the successor's tier, and the restore |
| + raise string |
| + }{ |
| + // The operator grew the host to large; the incumbent started at 512 MiB. |
| + {"a: operator size large over a standard incumbent", "large", nil, half, gib, |
| + fmt.Sprintf("raise:%d+%d", half, gib)}, |
| + // Grown live to xlarge, then the operator chose standard: the shrink |
| + // waits for a cold start. |
| + {"b: operator size standard under an xlarge incumbent", "standard", nil, two, two, |
| + fmt.Sprintf("raise:%d+%d", two, two)}, |
| + // No operator size: each artifact's own tier, byte-identical to main. |
| + {"c: no operator size keeps each artifact's tier", "", |
| + map[string]cgroup.Limit{"v1": cgroup.TierChildren, "v2": cgroup.TierDefault}, 0, half, |
| + fmt.Sprintf("raise:%d+%d", gib, half)}, |
| + // Grown live to xlarge, then the size cleared: the incumbent runs |
| + // above its build's tier, so the swap never lowers it. |
| + {"d: cleared size under an xlarge incumbent", "", nil, two, two, |
| + fmt.Sprintf("raise:%d+%d", two, two)}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + f := newSwapFixture(t) |
| + f.b.tiers = tc.tiers |
| + inc := f.incumbent |
| + inc.Tier = cgroup.Limit{MemoryMax: tc.inc} |
| + setCurrentGen(t, f.a, f.host, inc) |
| + f.a.mu.Lock() |
| + f.a.entries[f.host].route.Size = tc.size |
| + f.a.mu.Unlock() |
| + |
| + res := f.a.Swap(context.Background(), f.attempt(ModeOverlap), f.newest) |
| + if res.Outcome != SwapDone || res.Gen.Tier.MemoryMax != tc.succ { |
| + t.Fatalf("Swap = %+v, want done at %d", res, tc.succ) |
| + } |
| + if g, _ := f.b.lastGen(); g.Tier.MemoryMax != tc.succ { |
| + t.Fatalf("the successor spawned at %d, want %d", g.Tier.MemoryMax, tc.succ) |
| + } |
| + ev := f.b.events() |
| + if indexPrefix(ev, tc.raise) < 0 { |
| + t.Fatalf("events %v: want %s", ev, tc.raise) |
| + } |
| + // A bare "restore" is the wake's data restore; "restore:" is the |
| + // parent's. There is exactly one, to the successor's tier. |
| + var restores []string |
| + for _, e := range ev { |
| + if strings.HasPrefix(e, "restore:") { |
| + restores = append(restores, e) |
| + } |
| + } |
| + if want := fmt.Sprintf("restore:%d", tc.succ); len(restores) != 1 || restores[0] != want { |
| + t.Fatalf("parent restores %v, want only %s", restores, want) |
| + } |
| + }) |
| + } |
| +} |
| + |
| // The "swapped" event carries the retiring generation's drain time (spec |
| // §9.4), so the result measures it: from SIGTERM to the proven exit. |
| func TestSwapOverlapReportsTheDrainTime(t *testing.T) { |