| index c0a0f0431..3baa26ca1 100644 |
| --- a/internal/grouproll/sim_test.go |
| +++ b/internal/grouproll/sim_test.go |
| @@ -59,6 +59,10 @@ type simulation struct { |
| // last journaled row of each kind, kept as rows become durable. |
| rows map[string]Row |
| forbidden []string // complete, desired or terminate calls seen |
| + // lock is the seed's DR-4 lock (V13): "" none, "before" a lock names |
| + // the member from the start, "standby" one appears once it enters |
| + // Standby (between the two sweeps). |
| + lock string |
| } |
| |
| // runSeed runs one seed and returns its coverage, or the first failed |
| @@ -66,6 +70,12 @@ type simulation struct { |
| // (nil is Classify); the audited wrapper always runs around it. Each seed |
| // gets its own state directory under base, removed afterwards. |
| func runSeed(t *testing.T, base string, seed int64, classify func(Facts) Decision) (coverage map[string]int, err error) { |
| + return runSeedWith(t, base, seed, classify, nil) |
| +} |
| + |
| +// runSeedWith is runSeed with mutate applied to the seed's harness before |
| +// it runs (the executor mutants). |
| +func runSeedWith(t *testing.T, base string, seed int64, classify func(Facts) Decision, mutate func(h *harness)) (coverage map[string]int, err error) { |
| if classify == nil { |
| classify = Classify |
| } |
| @@ -86,6 +96,21 @@ func runSeed(t *testing.T, base string, seed int64, classify func(Facts) Decisio |
| s.h.classify = s.decide |
| s.h.beforeEvent = func(kind string, _ map[string]any) { s.journalStep("before", kind, nil) } |
| s.h.afterEvent = func(kind string, row Row) { s.journalStep("after", kind, row) } |
| + // The lock draws from its own source, so each seed's chaos draws are |
| + // not shifted by it. |
| + switch rand.New(rand.NewSource(seed ^ 0x5eedd4)).Intn(8) { |
| + case 0: |
| + s.lock = "before" |
| + s.f.locks["shop"] = heldLock(ref(fakeIID), fakeIID) |
| + case 1: |
| + s.lock = "standby" |
| + } |
| + if s.lock != "" { |
| + s.coverage["lock:"+s.lock]++ |
| + } |
| + if mutate != nil { |
| + mutate(s.h) |
| + } |
| defer func() { |
| if r := recover(); r != nil { |
| f, ok := r.(simFailure) |
| @@ -134,9 +159,15 @@ func (s *simulation) journalStep(when, kind string, row Row) { |
| s.chaos = true |
| } |
| switch kind { |
| - case "failed-probe", "return-hook", "divergence-held", "done": |
| + case "failed-probe", "return-hook", "divergence-held", "done", "lock-refused": |
| s.trace = append(s.trace, "journal:"+kind) |
| } |
| + switch kind { |
| + case "lock-refused": |
| + s.coverage["lock-refused"]++ |
| + case "done": |
| + s.coverage[fmt.Sprintf("outcome:%v", row["outcome"])]++ |
| + } |
| } |
| s.audit(when + ":journal:" + kind) |
| s.maybeDie(when + ":journal:" + kind) |
| @@ -239,11 +270,19 @@ func (s *simulation) request(op string, args map[string]any, write bool, perform |
| s.forbidden = append(s.forbidden, op) |
| s.fail("forbidden provider write") |
| } |
| + if op == "session" && args["verb"] == "apply" { |
| + // V13: DR-4 restarts the edge with no drain. |
| + s.check(f.locks["shop"] == nil, "apply while a lock names the member under DR-4") |
| + } |
| oldDesired := f.desired |
| result, err := perform() |
| if err != nil { |
| return nil, err |
| } |
| + if op == "enter" && s.lock == "standby" { |
| + // The member takes a lease after the first sweep. |
| + f.locks["shop"] = heldLock(ref(fakeIID), fakeIID) |
| + } |
| if op == "minimum" { |
| s.check(f.desired == oldDesired, "minimum raised desired") |
| } |
| @@ -415,6 +454,24 @@ func (s *simulation) run() map[string]int { |
| } |
| s.check(converged, "did not converge after fault injection stopped") |
| s.audit("end") |
| + outcome := s.rows["done"]["outcome"] |
| + if s.lock == "before" { |
| + // Refused up front: no group write, nothing to return. |
| + s.check(!s.active() && outcome == "floor-refused", "lock holder not refused up front") |
| + s.check(countOf(f.writes, "minimum") == 0 && countOf(f.writes, "enter") == 0, |
| + "group write before the DR-4 sweep") |
| + s.check(f.minimum == 2 && f.desired == 2 && f.maximum == 2 && f.states[fakeIID] == "InService", |
| + "DR-4 refusal changed the group") |
| + return s.coverage |
| + } |
| + if s.lock == "standby" { |
| + s.check(countOf(f.writes, "apply") == 0 && f.boxes[fakeIID]["binary_sha256"] == oldSHA, |
| + "lease holder not returned unchanged") |
| + s.check(s.last("lock-refused"), "lease after Standby not refused") |
| + if !f.hook { |
| + s.check(outcome == "lock-refused", "lease after Standby not closed lock-refused") |
| + } |
| + } |
| if f.hook { |
| if s.providerReturns { |
| s.check(s.last("divergence-held") && f.states[fakeIID] == "Standby", "hook return did not hold") |
| @@ -481,7 +538,8 @@ func TestSeededSimulation(t *testing.T) { |
| if count >= 50 { |
| for _, event := range []string{"describe-error", "diverged", "failed", "provider-return", "death", "resume", |
| "admission-drop", "admission-recovery", "loss:exit", "phase:ReturnHeld", "phase:Returning", |
| - "phase:Serving", "death:before-api", "death:after-api"} { |
| + "phase:Serving", "death:before-api", "death:after-api", "lock:before", "lock:standby", |
| + "lock-refused", "outcome:floor-refused", "outcome:lock-refused"} { |
| if coverage[event] == 0 { |
| t.Errorf("coverage %s = 0", event) |
| } |