Skip to content

Commit

Permalink
Merge #38532
Browse files Browse the repository at this point in the history
38532: storage: deflake TestReplicaRefreshPendingCommandsTicks r=tbg a=nvanbenschoten

Fixes #38525.

The test was occasionally failing because the proposals map was being refreshed
due to a `reasonNewLeaderOrConfigChange`. This was caused by 1ff3556, which
replaced `submitProposalFn` with `proposalBuf.testing.submitProposalFilter`. The
new approach to mocking out this function doesn't prevent a Raft ready iteration
from being scheduled, so `handleRaftReady` was being called and noticing the
leadership change, resulting in the refresh.

I've stressed this for 200,000 iterations without a failure.

Co-authored-by: Nathan VanBenschoten <[email protected]>
  • Loading branch information
craig[bot] and nvanbenschoten committed Jun 28, 2019
2 parents 537767a + 7d3583d commit 77e4611
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions pkg/storage/replica_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7533,22 +7533,20 @@ func TestReplicaRefreshPendingCommandsTicks(t *testing.T) {
defer stopper.Stop(context.TODO())
tc.StartWithStoreConfig(t, stopper, cfg)

// Grab Replica.raftMu in order to block normal raft replica processing. This
// test is ticking the replica manually and doesn't want the store to be
// doing so concurrently.
r := tc.repl

repDesc, err := tc.repl.GetReplicaDescriptor()
if err != nil {
t.Fatal(err)
}

// Only followers refresh pending commands during tick events. Change the
// replica that the range thinks is the leader so that the replica thinks
// it's a follower.
r.mu.Lock()
r.mu.leaderID = 2
r.mu.Unlock()
// Flush a write all the way through the Raft proposal pipeline. This
// ensures that leadership settles down before we start manually submitting
// proposals and that we don't see any unexpected proposal refreshes due to
// reasons like reasonNewLeaderOrConfigChange.
args := incrementArgs([]byte("a"), 1)
if _, pErr := tc.SendWrapped(&args); pErr != nil {
t.Fatal(pErr)
}

electionTicks := tc.store.cfg.RaftElectionTimeoutTicks
{
Expand Down

0 comments on commit 77e4611

Please sign in to comment.