Browse Source

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.
Xiang Li 9 years ago
parent
commit
2fa5b913fe
1 changed files with 2 additions and 2 deletions
  1. 2 2
      raft/raft_paper_test.go

+ 2 - 2
raft/raft_paper_test.go

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