diff --git a/pkg/kv/kvserver/replica_raft.go b/pkg/kv/kvserver/replica_raft.go index d2665cb1b21a..cd2eedca1366 100644 --- a/pkg/kv/kvserver/replica_raft.go +++ b/pkg/kv/kvserver/replica_raft.go @@ -32,6 +32,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/storage" "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/cockroach/pkg/util/encoding" "github.com/cockroachdb/cockroach/pkg/util/hlc" "github.com/cockroachdb/cockroach/pkg/util/humanizeutil" @@ -1598,6 +1599,15 @@ func (r *Replica) deliverLocalRaftMsgsRaftMuLockedReplicaMuLocked( } r.localMsgs.Unlock() + // If we are in a test build, shuffle the local messages before delivering + // them. These are not required to be in order, so ensure that re-ordering is + // handled properly. + if buildutil.CrdbTestBuild { + rand.Shuffle(len(localMsgs), func(i, j int) { + localMsgs[i], localMsgs[j] = localMsgs[j], localMsgs[i] + }) + } + for i, m := range localMsgs { if err := raftGroup.Step(m); err != nil { log.Fatalf(ctx, "unexpected error stepping local raft message [%s]: %v",