diff --git a/seaweed-block/core/host/volume/peer_reconcile_attestation_test.go b/seaweed-block/core/host/volume/peer_reconcile_attestation_test.go new file mode 100644 index 0000000000..ddd4728713 --- /dev/null +++ b/seaweed-block/core/host/volume/peer_reconcile_attestation_test.go @@ -0,0 +1,61 @@ +package volume + +import ( + "testing" + + "github.com/seaweedfs/seaweed-block/core/replication" + "github.com/seaweedfs/seaweed-block/core/storage" + "github.com/seaweedfs/seaweed-block/core/transport" +) + +type reconcileAttestationStore struct{ *storage.BlockStore } + +func (*reconcileAttestationStore) StoreID() storage.StoreID { return storage.StoreID{2} } + +// TestPublishHealthyDoesNotRaceStoreAttestation exercises the production heal +// entry point while UpdateReplicaSet's asynchronous store learner is admitted. +// Both exchanges use a real replica connection. Repetition exposes logical +// frame ownership races that the Go memory race detector cannot detect. +func TestPublishHealthyDoesNotRaceStoreAttestation(t *testing.T) { + for attempt := 0; attempt < 500; attempt++ { + func() { + replica := &reconcileAttestationStore{storage.NewBlockStore(64, 4096)} + listener, err := transport.NewReplicaListener("127.0.0.1:0", replica) + if err != nil { + t.Fatal(err) + } + listener.Serve() + defer listener.Stop() + + v := replication.NewReplicationVolume("v", storage.NewBlockStore(64, 4096)) + defer v.Close() + epochs, err := transport.LoadEpochTable("", "v") + if err != nil { + t.Fatal(err) + } + v.SetEpochTable(epochs) + v.RequireAttestedStores() + var peer *replication.ReplicaPeer + if err := v.ConfigurePeerLifecycleHook(func(p *replication.ReplicaPeer) { peer = p }, func(string) {}); err != nil { + t.Fatal(err) + } + target := replication.ReplicaTarget{ + ReplicaID: "r2", DataAddr: listener.Addr(), ControlAddr: listener.Addr(), + Epoch: 1, EndpointVersion: 1, StoreID: replica.StoreID(), + } + if err := v.UpdateReplicaSet(1, []replication.ReplicaTarget{target}); err != nil { + t.Fatal(err) + } + if peer == nil { + t.Fatal("membership update did not install the replica") + } + exec := NewPeerCommandExecutor(peer) + for exchange := 0; exchange < 2; exchange++ { + exec.PublishHealthy("r2") + if got := peer.State(); got != replication.ReplicaHealthy { + t.Fatalf("attempt %d exchange %d: caught-up replica degraded during store attestation: %s", attempt, exchange, got) + } + } + }() + } +}