rollout: the requeue probe reads the retry log, not the drained map
TestAPointerClearRequeuesBeforeTheNextChannelIsRead failed on CI with "requeued only after every channel was read" when the requeue had in fact come first. The probe checked len(m.retried) at the second pointer read, but retryBuild pokes the scheduler, whose goroutine may attempt the build and delete that entry before the read. Under load it did. The harness now keeps the manager's log lines, and the probe asks whether "build v2 retried" was logged before the second read. Still catches the regression: with the requeue moved after every channel read, the test fails 3 of 3. 50 of 50 pass unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+25
−5
internal/rollout/fake_test.go+22 −1internal/rollout/manager_test.go+3 −4
diff --git a/internal/rollout/fake_test.go b/internal/rollout/fake_test.go| index f6e5c20d7..b6c1738c7 100644 |
| --- a/internal/rollout/fake_test.go |
| +++ b/internal/rollout/fake_test.go |
| @@ -445,6 +445,27 @@ type harness struct { |
| // policyHook, when set, runs at the start of every policy load, with no |
| // lock held: a test's window into the planner's policy read. |
| policyHook func() |
| + // logMu guards logs, the manager's log lines, in order. |
| + logMu sync.Mutex |
| + logs []string |
| +} |
| + |
| +func (h *harness) logf(f string, args ...any) { |
| + h.logMu.Lock() |
| + defer h.logMu.Unlock() |
| + h.logs = append(h.logs, fmt.Sprintf(f, args...)) |
| +} |
| + |
| +// logged reports whether the manager has logged a line containing s. |
| +func (h *harness) logged(s string) bool { |
| + h.logMu.Lock() |
| + defer h.logMu.Unlock() |
| + for _, l := range h.logs { |
| + if strings.Contains(l, s) { |
| + return true |
| + } |
| + } |
| + return false |
| } |
| func newHarness(t *testing.T, hosts ...string) *harness { |
| @@ -467,7 +488,7 @@ func newHarness(t *testing.T, hosts ...string) *harness { |
| h.m = NewManager(ctx, Deps{ |
| Act: h.probe, Routes: h.rows, Book: h.book, OptDir: h.opt, DataDir: h.data, Box: "box-1", |
| Demand: h.demand, Policy: h.policy, Pointer: h.pointerFor, Events: h.events, |
| - Touch: func() { h.touched.Add(1) }, Now: h.clock, Logf: func(string, ...any) {}, |
| + Touch: func() { h.touched.Add(1) }, Now: h.clock, Logf: h.logf, |
| }) |
| return h |
| } |
diff --git a/internal/rollout/manager_test.go b/internal/rollout/manager_test.go| index 8506c1cdc..138017436 100644 |
| --- a/internal/rollout/manager_test.go |
| +++ b/internal/rollout/manager_test.go |
| @@ -1168,10 +1168,9 @@ func TestAPointerClearRequeuesBeforeTheNextChannelIsRead(t *testing.T) { |
| if reads.Add(1) != 2 { |
| return |
| } |
| - h.m.mu.Lock() |
| - n := len(h.m.retried) |
| - h.m.mu.Unlock() |
| - if n == 0 { |
| + // Not len(m.retried): retryBuild pokes the scheduler, which may |
| + // attempt the build and clear its entry before this second read. |
| + if !h.logged("build v2 retried") { |
| requeuedLate.Store(true) |
| } |
| } |