From 931cf3454a13488015569ed47aec4007d3d6a37a Mon Sep 17 00:00:00 2001 From: Xiang Date: Wed, 1 Mar 2017 17:35:55 -0800 Subject: [PATCH] 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. --- raft/node_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/raft/node_test.go b/raft/node_test.go index ec3c74515..ba604ee86 100644 --- a/raft/node_test.go +++ b/raft/node_test.go @@ -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)