raft: fix flaky test

We recently changed the randomized election timeout from (et, 2*et-1] tp
[et, 2*et-2], where et is user set election timeout.

So 2*et might trigger two elections instead of one. We need to fix the test
code accordingly.

Thanks for Tikv guys for finding this issue. We probably need to randomize
etcd/raft test more.
This commit is contained in:
Xiang Li 2016-05-02 21:04:53 -07:00
parent a8139e2b0e
commit 2fa5b913fe

View File

@ -159,7 +159,7 @@ func testNonleaderStartElection(t *testing.T, state StateType) {
r.becomeCandidate()
}
for i := 0; i < 2*et; i++ {
for i := 1; i < 2*et; i++ {
r.tick()
}
@ -785,7 +785,7 @@ func TestVoteRequest(t *testing.T) {
})
r.readMessages()
for i := 0; i < r.electionTimeout*2; i++ {
for i := 1; i < r.electionTimeout*2; i++ {
r.tickElection()
}