| index baa9a5c3b..d80cd29a3 100644 |
| --- a/internal/grouproll/depart_test.go |
| +++ b/internal/grouproll/depart_test.go |
| @@ -1575,3 +1575,80 @@ func TestDepartUnansweredRestoreRecovers(t *testing.T) { |
| }) |
| } |
| } |
| + |
| +// Astra P1-2 (the r2 cut, departing from the script): an exit-intent row |
| +// is written before ExitStandby is sent, so it proves nothing about the |
| +// drain. A failed drain's return cut after that row, then resumed while |
| +// the drain status is unknown or running, stops drain-moving and sends no |
| +// ExitStandby. |
| +func TestDepartReturnCutAfterExitIntentRechecksDrain(t *testing.T) { |
| + for _, status := range []string{"unknown", "running"} { |
| + t.Run(status, func(t *testing.T) { |
| + h := newHeldHarness(t, 2, nil) |
| + h.f.held.drainMode = "drop-done" |
| + h.f.before = func(op string, _ map[string]any) error { |
| + if op == "exit" { |
| + panic(fakeDeath{"exit"}) |
| + } |
| + return nil |
| + } |
| + if !expectDeath(t, func() { h.depart("replace", heldTx) }) { |
| + t.Fatal("no cut at ExitStandby") |
| + } |
| + if _, ok := h.txJournal(heldTx).Last("exit-intent", nil); !ok || h.f.states[fakeIID] != "Standby" { |
| + t.Fatalf("exit-intent %v state %s", ok, h.f.states[fakeIID]) |
| + } |
| + h.f.before = nil |
| + h.f.held.statusDrain = unknownDrain |
| + if status == "running" { |
| + h.f.held.statusDrain = func(map[string]any) map[string]any { |
| + return map[string]any{"state": "known", "incarnation": heldIncarnation, |
| + "transaction": heldTx, "step": "move", "result": "running"} |
| + } |
| + } |
| + calls := len(h.f.calls) |
| + if err := h.resume(); !isStop(err, "drain-moving") { |
| + t.Fatalf("resume = %v, want drain-moving", err) |
| + } |
| + for _, c := range h.f.calls[calls:] { |
| + if c.Op == "exit" { |
| + t.Fatal("ExitStandby sent while the drain may still move hosts") |
| + } |
| + } |
| + if h.f.states[fakeIID] != "Standby" || h.activeTx() != heldTx { |
| + t.Fatalf("state %s active %q", h.f.states[fakeIID], h.activeTx()) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// Astra P1-2: an ExitStandby refused before dispatch because its |
| +// observation expired leaves an exit-intent row behind. The resumed |
| +// attempt, with the drain status now unknown, stops drain-moving with no |
| +// ExitStandby. |
| +func TestDepartExpiredExitAttemptRechecksDrain(t *testing.T) { |
| + h := newHeldHarness(t, 2, nil) |
| + h.f.held.drainMode = "drop-done" |
| + expired := false |
| + h.beforeEvent = func(kind string, _ map[string]any) { |
| + if kind == "exit-intent" && !expired { |
| + expired = true |
| + h.f.now = h.f.now.Add(10 * time.Second) |
| + h.f.held.statusDrain = unknownDrain |
| + } |
| + } |
| + // The expired attempt stops the run as an operation error (admission). |
| + if err := h.depart("replace", heldTx); refusalKey(err) != "admission" || !expired { |
| + t.Fatalf("depart = %v (exit-intent %v), want admission", err, expired) |
| + } |
| + if err := h.resume(); !isStop(err, "drain-moving") { |
| + t.Fatalf("resume = %v, want drain-moving", err) |
| + } |
| + j := h.txJournal(heldTx) |
| + if r, _ := j.Last("error", map[string]any{"op": "exit"}); r["error"] != "ObservationExpired" || r["dispatched"] != false { |
| + t.Fatalf("exit error row %v", r) |
| + } |
| + if countOf(h.verbs(), "exit") != 0 || h.f.states[fakeIID] != "Standby" { |
| + t.Fatalf("verbs %v state %s", h.verbs(), h.f.states[fakeIID]) |
| + } |
| +} |