From c827c7432c21e34c9d9e6ba34e414ba7abc39473 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Sun, 31 Jan 2016 12:41:33 -0800 Subject: [PATCH] raft: fix leaky goroutines in raft test --- raft/example_test.go | 1 + raft/node_test.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/raft/example_test.go b/raft/example_test.go index 876b38d5c..38dc95b47 100644 --- a/raft/example_test.go +++ b/raft/example_test.go @@ -26,6 +26,7 @@ func saveToDisk(ents []pb.Entry) {} func ExampleNode() { c := &Config{} n := StartNode(c, nil) + defer n.Stop() // stuff to n happens in other goroutines diff --git a/raft/node_test.go b/raft/node_test.go index 92ada103e..96d34336e 100644 --- a/raft/node_test.go +++ b/raft/node_test.go @@ -330,6 +330,7 @@ func TestNodeStart(t *testing.T) { MaxInflightMsgs: 256, } n := StartNode(c, []Peer{{ID: 1}}) + defer n.Stop() n.Campaign(ctx) g := <-n.Ready() if !reflect.DeepEqual(g, wants[0]) { @@ -379,6 +380,7 @@ func TestNodeRestart(t *testing.T) { MaxInflightMsgs: 256, } n := RestartNode(c) + defer n.Stop() if g := <-n.Ready(); !reflect.DeepEqual(g, want) { t.Errorf("g = %+v,\n w %+v", g, want) } @@ -423,6 +425,7 @@ func TestNodeRestartFromSnapshot(t *testing.T) { MaxInflightMsgs: 256, } n := RestartNode(c) + defer n.Stop() if g := <-n.Ready(); !reflect.DeepEqual(g, want) { t.Errorf("g = %+v,\n w %+v", g, want) } else { @@ -450,6 +453,7 @@ func TestNodeAdvance(t *testing.T) { MaxInflightMsgs: 256, } n := StartNode(c, []Peer{{ID: 1}}) + defer n.Stop() n.Campaign(ctx) <-n.Ready() n.Propose(ctx, []byte("foo"))