Browse Source

Merge pull request #6097 from swingbach/master

raft: fix #6096
Xiang Li 9 years ago
parent
commit
c46955b60a
1 changed files with 5 additions and 0 deletions
  1. 5 0
      raft/raft_test.go

+ 5 - 0
raft/raft_test.go

@@ -1295,6 +1295,10 @@ func TestLeaderElectionWithCheckQuorum(t *testing.T) {
 		t.Errorf("state = %s, want %s", c.state, StateFollower)
 		t.Errorf("state = %s, want %s", c.state, StateFollower)
 	}
 	}
 
 
+	// need to reset randomizedElectionTimeout larger than electionTimeout again,
+	// because the value might be reset to electionTimeout since the last state changes
+	setRandomizedElectionTimeout(a, a.electionTimeout+1)
+	setRandomizedElectionTimeout(b, b.electionTimeout+2)
 	for i := 0; i < a.electionTimeout; i++ {
 	for i := 0; i < a.electionTimeout; i++ {
 		a.tick()
 		a.tick()
 	}
 	}
@@ -2225,6 +2229,7 @@ func TestLeaderTransferWithCheckQuorum(t *testing.T) {
 	for i := 1; i < 4; i++ {
 	for i := 1; i < 4; i++ {
 		r := nt.peers[uint64(i)].(*raft)
 		r := nt.peers[uint64(i)].(*raft)
 		r.checkQuorum = true
 		r.checkQuorum = true
+		setRandomizedElectionTimeout(r, r.electionTimeout+i)
 	}
 	}
 
 
 	// Letting peer 2 electionElapsed reach to timeout so that it can vote for peer 1
 	// Letting peer 2 electionElapsed reach to timeout so that it can vote for peer 1