carlos / platform Public

grouproll: DR-4 lock seeds and a skipped-sweep mutant in the simulation

One seed in eight starts with a lock naming the member, one in eight
gets one once the member is in Standby. An apply while a lock names the
member fails an audit; the skipDR4Locks mutant is caught at seed 3.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev e5588c185c6b3b98c77884734b3fe0ca4c84732d parent 95514fb
2 files changed, +80 −2
  • internal/grouproll/mutation_test.go +20 −0
  • internal/grouproll/sim_test.go +60 −2
diff --git a/internal/grouproll/mutation_test.go b/internal/grouproll/mutation_test.go
index 96cba8e7c..c0b466547 100644
--- a/internal/grouproll/mutation_test.go
+++ b/internal/grouproll/mutation_test.go
@@ -112,6 +112,26 @@ func TestRequiredMutations(t *testing.T) {
}
}
+// TestDR4LockMutation: a DR-4 roll that never sweeps the locks (the
+// script's behaviour, V13) restarts a lease-holding member, and the roll
+// simulation's apply audit catches it within 100 seeds.
+func TestDR4LockMutation(t *testing.T) {
+ base := stateRoot(t)
+ for seed := int64(0); seed < 100; seed++ {
+ _, err := runSeedWith(t, base, seed, nil, func(h *harness) { h.seams.skipDR4Locks = true })
+ if err == nil {
+ continue
+ }
+ first := strings.SplitN(strings.TrimPrefix(err.Error(), fmt.Sprintf("seed=%d: ", seed)), "\n", 2)[0]
+ if first != "apply while a lock names the member under DR-4" {
+ t.Fatalf("mutant failed on another audit: %v", err)
+ }
+ t.Logf("DR-4 lock mutation caught: seed %d: %s", seed, first)
+ return
+ }
+ t.Fatal("skipping the DR-4 lock sweeps survived the simulation")
+}
+
// TestDepartMutations: the planned handovers' required mutants, each an
// executor seam, must fail the depart simulation's audits within 100
// seeds, on the audit that names it.
diff --git a/internal/grouproll/sim_test.go b/internal/grouproll/sim_test.go
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)
}