cutover witness: check the drain state before releasing the CLI
Human
Prompt
find why TestQueuedFleetRunAtACutoverExpiresByTheCLI fails in CI only on edge-held-streams-432 (#432), and fix the cause.
From this commit's own message. The prompt ledger has no entries for it — which is what a squashed, rebased or amended commit looks like, and what every commit looks like in a repo without a ledger.
Summary
drive ran its "at activation" checks after sending the t0+70 step's done, which releases the CLI. Its next poll expires the run (the gate is now on), so a descheduled test goroutine read the record after the CLI's expire POST: state expired by the member. A delay injected there fails every run. The checks now run inside the t0+70 step while the CLI is parked with no request in flight, and drive returns the expire-answer count taken then, which the ByTheCLI test used to read after the release (the same race). Latent since rootfs Plan 6 (11c8c864); this branch's heavier CI load exposed it. Test-only.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+35
−25
run_cutover_witness_test.go+35 −25
CI passed — run details
diff --git a/run_cutover_witness_test.go b/run_cutover_witness_test.go| index e7cc5e10a..88ce54ea0 100644 |
| --- a/run_cutover_witness_test.go |
| +++ b/run_cutover_witness_test.go |
| @@ -378,8 +378,9 @@ func (w *cutoverWorld) follow(stderr *bytes.Buffer) (<-chan step, <-chan int) { |
| // drive steps the CLI through fake time to t0+70: the drain at t0+10, the |
| // box's dial at t0+20 and its two later passes (which do not dial: it let |
| // the run go), the CLI still following at t0+69, and activation at t0+70. |
| -// It returns once activation is done, with the CLI's next wait released. |
| -func (w *cutoverWorld) drive(t *testing.T, steps <-chan step, exit <-chan int, stderr *bytes.Buffer) { |
| +// It returns once activation is done, with the CLI's next wait released, |
| +// and the number of expire answers logged before that release. |
| +func (w *cutoverWorld) drive(t *testing.T, steps <-chan step, exit <-chan int, stderr *bytes.Buffer) int { |
| t.Helper() |
| type event struct { |
| at time.Duration |
| @@ -399,6 +400,35 @@ func (w *cutoverWorld) drive(t *testing.T, steps <-chan step, exit <-chan int, s |
| w.boxDial(t) |
| letGo[w.id] = true |
| } |
| + // atActivation checks the drain's end state. It runs inside the t0+70 |
| + // step, before that step's wait is released: the CLI is parked in |
| + // runTerm.after with no request in flight, so its next poll (which |
| + // expires the run once the gate is on) cannot race these reads. |
| + logged := 0 |
| + atActivation := func() { |
| + if dials != 1 || w.doorHits.Load() != 1 { |
| + t.Fatalf("%d box dials, %d run door requests, want 1", dials, w.doorHits.Load()) |
| + } |
| + // From t0+60 to activation every expire POST answered 503, and there |
| + // was one about every second. |
| + n := 0 |
| + for _, a := range w.log.all() { |
| + if a.at.Before(w.t0.Add(60 * time.Second)) { |
| + t.Fatalf("an expire POST before t0+60: %+v", a) |
| + } |
| + if a.status != http.StatusServiceUnavailable { |
| + t.Fatalf("an expire POST during the drain answered %d %s, want 503", a.status, a.body) |
| + } |
| + n++ |
| + } |
| + if n < 9 { |
| + t.Fatalf("%d expire POSTs from t0+60 to t0+69, want about one a second", n) |
| + } |
| + logged = n |
| + if rec, _ := w.record(t); rec.ActiveRun == nil || rec.ActiveRun.State != provision.RunQueued || rec.ActiveRun.Box != "" { |
| + t.Fatalf("at activation the run is %+v, want still queued and never picked", rec.ActiveRun) |
| + } |
| + } |
| activated := false |
| events := []*event{ |
| {at: 10 * time.Second, do: func() { w.cutover(t) }}, |
| @@ -414,6 +444,7 @@ func (w *cutoverWorld) drive(t *testing.T, steps <-chan step, exit <-chan int, s |
| w.srv.LifetimesWatchOnceForTest(context.Background()) |
| activated = true |
| w.log.armed.Store(w.holdFirstExpire) |
| + atActivation() |
| }}, |
| } |
| for !activated { |
| @@ -433,27 +464,7 @@ func (w *cutoverWorld) drive(t *testing.T, steps <-chan step, exit <-chan int, s |
| t.Fatal("the CLI asked for no wait in 30 s") |
| } |
| } |
| - if dials != 1 || w.doorHits.Load() != 1 { |
| - t.Fatalf("%d box dials, %d run door requests, want 1", dials, w.doorHits.Load()) |
| - } |
| - // From t0+60 to activation every expire POST answered 503, and there |
| - // was one about every second. |
| - n := 0 |
| - for _, a := range w.log.all() { |
| - if a.at.Before(w.t0.Add(60 * time.Second)) { |
| - t.Fatalf("an expire POST before t0+60: %+v", a) |
| - } |
| - if a.status != http.StatusServiceUnavailable { |
| - t.Fatalf("an expire POST during the drain answered %d %s, want 503", a.status, a.body) |
| - } |
| - n++ |
| - } |
| - if n < 9 { |
| - t.Fatalf("%d expire POSTs from t0+60 to t0+69, want about one a second", n) |
| - } |
| - if rec, _ := w.record(t); rec.ActiveRun == nil || rec.ActiveRun.State != provision.RunQueued || rec.ActiveRun.Box != "" { |
| - t.Fatalf("at activation the run is %+v, want still queued and never picked", rec.ActiveRun) |
| - } |
| + return logged |
| } |
| // finishExit steps the CLI on to its exit and wants exit 3 with exactly |
| @@ -556,8 +567,7 @@ func TestQueuedFleetRunAtACutoverExpiresByTheCLI(t *testing.T) { |
| var stderr bytes.Buffer |
| atAck := w.snapshotAtAck(t) |
| steps, exit := w.follow(&stderr) |
| - w.drive(t, steps, exit, &stderr) |
| - before := len(w.log.all()) |
| + before := w.drive(t, steps, exit, &stderr) |
| w.finishExit(t, steps, exit, &stderr) |
| answers := w.log.all()[before:] |
| if len(answers) != 1 || answers[0].status != http.StatusOK || !strings.Contains(answers[0].body, provision.RunExpired) { |