test: reproduce false readiness and retained settled replica coverage

This commit is contained in:
pingqiu committed 2026-11-20 05:17:12 -08:00
1 parent 7261411c46
commit 61274080b0
2 files changed
+83

No files matched your search

@@ -0,0 +1,29 @@
package engine
import "testing"
func TestPromotionReadyRefusesDelayedProbeDuringNewRecovery(t *testing.T) {
st := helperPrime(t, 50, 10, 100)
Apply(st, SessionPrepared{ReplicaID: "r1", SessionID: 1, Kind: SessionCatchUp, FrontierHint: 100})
Apply(st, SessionClosedCompleted{ReplicaID: "r1", SessionID: 1, AchievedLSN: 100})
Apply(st, DurableAckObserved{ReplicaID: "r1", EndpointVersion: 1, TransportEpoch: 1, DurableLSN: 100, PrimaryTailLSN: 10, PrimaryHeadLSN: 100})
Apply(st, RecoveryFactsObserved{ReplicaID: "r1", EndpointVersion: 1, TransportEpoch: 1, R: 100, S: 10, H: 150})
Apply(st, SessionPrepared{ReplicaID: "r1", SessionID: 2, Kind: SessionCatchUp, FrontierHint: 150})
Apply(st, RecoveryFactsObserved{ReplicaID: "r1", EndpointVersion: 1, TransportEpoch: 1, R: 50, S: 10, H: 100})
if fact := BuildPromotionReadyFact(st); fact.Ready {
t.Fatalf("active recovery became promotion ready after delayed probe: %+v", fact)
}
}
func TestMissingProbeAckRestoresNewerDurableProgress(t *testing.T) {
st := helperPrime(t, 50, 10, 100)
Apply(st, SessionPrepared{ReplicaID: "r1", SessionID: 1, Kind: SessionCatchUp, FrontierHint: 100})
Apply(st, SessionClosedCompleted{ReplicaID: "r1", SessionID: 1, AchievedLSN: 100})
Apply(st, RecoveryFactsObserved{ReplicaID: "r1", EndpointVersion: 1, TransportEpoch: 1})
result := Apply(st, DurableAckObserved{ReplicaID: "r1", EndpointVersion: 1, TransportEpoch: 1, DurableLSN: 150, PrimaryTailLSN: 110, PrimaryHeadLSN: 150})
if st.Recovery.R != 150 || st.Recovery.Decision != DecisionNone {
t.Fatalf("missing-probe ACK retained stale progress: R=%d decision=%s", st.Recovery.R, st.Recovery.Decision)
}
assertNoCommand(t, result, "StartRebuild")
assertNoCommand(t, result, "StartCatchUp")
}
@@ -0,0 +1,54 @@
package replication
import (
"net"
"testing"
"time"
"github.com/seaweedfs/seaweed-block/core/transport"
)
func TestApplyGate_WireSessionTurnoverRetiresSettledCoverage(t *testing.T) {
gate, store := newGate(t)
listener, err := transport.NewReplicaListenerWithFloorAndApplyHook("127.0.0.1:0", store, "v1", "", gate)
if err != nil {
t.Fatal(err)
}
if err := listener.AdmitAsReplica(1); err != nil {
listener.StopHard()
t.Fatal(err)
}
listener.Serve()
t.Cleanup(listener.StopHard)
for session := uint64(1); session <= 128; session++ {
c, err := net.DialTimeout("tcp", listener.Addr(), time.Second)
if err != nil {
t.Fatal(err)
}
if err := c.SetDeadline(time.Now().Add(2 * time.Second)); err != nil {
c.Close()
t.Fatal(err)
}
l := liveLineage(session)
err = transport.WriteMsg(c, transport.MsgShipEntry, transport.EncodeShipEntry(transport.ShipEntry{Lineage: l, LBA: 5, LSN: session, Data: makeData(byte(session))}))
if err == nil {
err = transport.WriteMsg(c, transport.MsgBarrierReq, transport.EncodeLineage(l))
}
if err == nil {
_, _, err = transport.ReadMsg(c)
}
c.Close()
if err != nil {
t.Fatal(err)
}
if session > 1 {
if _, _, _, found := gate.SessionState(session - 1); found {
t.Fatalf("settled session coverage survived turnover: session=%d", session-1)
}
}
}
// Retirement must leave the shared suffix version intact.
if err := gate.ApplyLive(liveLineage(129), 5, makeData(0), 127); err == nil {
t.Fatal("coverage retirement erased shared version")
}
}