raft: make TestNodeTick reliable

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.
release-3.2
Xiang 2017-03-01 17:35:55 -08:00
parent 010cc287bb
commit 931cf3454a
1 changed files with 5 additions and 1 deletions

View File

@ -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)