Fixed goroutine leak in server/etcdserver/raft_test.go
@@ -168,12 +168,8 @@ func TestStopRaftWhenWaitingForApplyDone(t *testing.T) {
srv := &EtcdServer{lgMu: new(sync.RWMutex), lg: zaptest.NewLogger(t), r: *r}
srv.r.start(nil)
n.readyc <- raft.Ready{}
- select {
- case <-srv.r.applyc:
- case <-time.After(time.Second):
- t.Fatalf("failed to receive toApply struct")
- }
+ stop := func() {
srv.r.stopped <- struct{}{}
select {
case <-srv.r.done:
@@ -182,6 +178,16 @@ func TestStopRaftWhenWaitingForApplyDone(t *testing.T) {
}
}
+ select {
+ case <-srv.r.applyc:
+ case <-time.After(time.Second):
+ stop()
+ t.Fatalf("failed to receive toApply struct")
+ }
+
+ stop()
+}
+
// TestConfigChangeBlocksApply ensures toApply blocks if committed entries contain config-change.
func TestConfigChangeBlocksApply(t *testing.T) {
n := newNopReadyNode()
