Skip to content

Commit

Permalink
kv: shuffle local raft messages before delivery in tests
Browse files Browse the repository at this point in the history
This commit adds a testing facility to shuffle local raft messages before
delivering them to the raft state machine. These are not required to be in
order, so we shuffle in tests ensure that re-ordering is handled properly.
  • Loading branch information
nvanbenschoten committed Jan 31, 2023
1 parent e59b8a0 commit 1c2135f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/kv/kvserver/replica_raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 1c2135f

Please sign in to comment.