From 44bdfa6ca795bea19b82db41f49b33bbe8c507e5 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 25 Nov 2026 14:21:45 -0800 Subject: [PATCH] master: test that an old probe round's late answer is refused by a new round Co-Authored-By: Claude Opus 5.5 --- .../master/probe_round_late_answer_test.go | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 seaweed-block/core/host/master/probe_round_late_answer_test.go diff --git a/seaweed-block/core/host/master/probe_round_late_answer_test.go b/seaweed-block/core/host/master/probe_round_late_answer_test.go new file mode 100644 index 0000000000..cf3eece67e --- /dev/null +++ b/seaweed-block/core/host/master/probe_round_late_answer_test.go @@ -0,0 +1,53 @@ +package master + +import ( + "sync" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/authority" + "github.com/seaweedfs/seaweed-block/core/rpc/control" +) + +// An answer to an OLD round that arrives late, while a NEW round of the same +// volume and replica is open, is refused: it is evidence of another moment, +// so the new round never counts it (the new round sees no answer from r2). +func TestProbeRound_AnOldRoundsLateAnswerIsRefusedByTheNewRound(t *testing.T) { + hub := newProbeHub() + p := &roundEvidenceProvider{hub: hub, serverOf: func(_, r string) string { return "s2" }, ackProfile: "sync_quorum", wait: 200 * time.Millisecond, attested: attestedAs} + + var mu sync.Mutex + var held *control.ProbeAnswer // round A's answer, held back + delivered := make(chan bool, 1) + roundNode(t, hub, "s2", func(r *control.ProbeRound) *control.ProbeAnswer { + mu.Lock() + defer mu.Unlock() + if held == nil { + held = readyAnswer("s2")(r) // round A: answer later + held.DurableEnd = 99 + return nil + } + // round B: only round A's answer arrives now; B's own never does. + delivered <- hub.deliver(held) + return nil + }) + + ask := []authority.ReplicaCandidate{{ReplicaID: "r2", ServerID: "s2"}} + a, err := p.ProbePromotionCandidates("v1", authority.AuthorityBasis{}, ask) + if err != nil { + t.Fatal(err) + } + if len(a.Candidates) != 1 || a.Candidates[0].Ready { + t.Fatalf("round A (no answer in time): %+v", a.Candidates) + } + b, err := p.ProbePromotionCandidates("v1", authority.AuthorityBasis{}, ask) + if err != nil { + t.Fatal(err) + } + if ok := <-delivered; ok { + t.Fatal("the hub accepted round A's answer while round B was open") + } + if len(b.Candidates) != 1 || b.Candidates[0].Ready || b.Candidates[0].DurableLSN != 0 { + t.Fatalf("round B counted round A's late answer: %+v", b.Candidates) + } +}