Skip to content

Commit

Permalink
raft: make TestNodeTick reliable
Browse files Browse the repository at this point in the history
TestNodeTick relies on a unreliable func `waitForSchedule` when running
with GOMAXPROCS > 1. This commit changes the test to make sure we stop
the node afte it drains the tick chan. The test should be reliable now.
  • Loading branch information
xiang90 committed Mar 2, 2017
1 parent 010cc28 commit 931cf34
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion raft/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,11 @@ func TestNodeTick(t *testing.T) {
go n.run(r)
elapsed := r.electionElapsed
n.Tick()
testutil.WaitSchedule()

for len(n.tickc) != 0 {
time.Sleep(100 * time.Millisecond)
}

n.Stop()
if r.electionElapsed != elapsed+1 {
t.Errorf("elapsed = %d, want %d", r.electionElapsed, elapsed+1)
Expand Down

0 comments on commit 931cf34

Please sign in to comment.