Skip to content

Commit

Permalink
Merge pull request #17365 from fuweid/fix-race
Browse files Browse the repository at this point in the history
etcdserver: drain leaky goroutines before test completed
  • Loading branch information
ahrtr authored Feb 5, 2024
2 parents 43d6759 + 32ee8b8 commit 9281739
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions server/etcdserver/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ func TestBootstrapBackend(t *testing.T) {
st := v2store.New(StoreClusterPrefix, StoreKeysPrefix)
ss := snap.New(cfg.Logger, cfg.SnapDir())
backend, err := bootstrapBackend(cfg, haveWAL, st, ss)
defer t.Cleanup(func() {
backend.Close()
})

hasError := err != nil
expectedHasError := tt.expectedError != nil
Expand Down
3 changes: 3 additions & 0 deletions server/etcdserver/corrupt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,9 @@ func TestHashKVHandler(t *testing.T) {
be, _ := betesting.NewDefaultTmpBackend(t)
defer betesting.Close(t, be)
etcdSrv.kv = mvcc.New(zap.NewNop(), be, &lease.FakeLessor{}, mvcc.StoreConfig{})
defer func() {
assert.NoError(t, etcdSrv.kv.Close())
}()
ph := &hashKVHandler{
lg: zap.NewNop(),
server: etcdSrv,
Expand Down
2 changes: 1 addition & 1 deletion server/etcdserver/raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func TestConfigChangeBlocksApply(t *testing.T) {
updateLead: func(uint64) {},
updateLeadership: func(bool) {},
})
defer srv.r.Stop()
defer srv.r.stop()

n.readyc <- raft.Ready{
SoftState: &raft.SoftState{RaftState: raft.StateFollower},
Expand Down
13 changes: 13 additions & 0 deletions server/etcdserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func TestApplyRepeat(t *testing.T) {
st := v2store.New()
cl.SetStore(v2store.New())
be, _ := betesting.NewDefaultTmpBackend(t)
defer betesting.Close(t, be)
cl.SetBackend(schema.NewMembershipBackend(lg, be))

cl.AddMember(&membership.Member{ID: 1234}, true)
Expand Down Expand Up @@ -201,6 +202,7 @@ func TestV2SetClusterVersion(t *testing.T) {
func TestApplyConfStateWithRestart(t *testing.T) {
n := newNodeRecorder()
srv := newServer(t, n)
defer srv.Cleanup()

assert.Equal(t, srv.consistIndex.ConsistentIndex(), uint64(0))

Expand Down Expand Up @@ -476,6 +478,7 @@ func TestApplyConfigChangeUpdatesConsistIndex(t *testing.T) {
consistIndex: ci,
beHooks: serverstorage.NewBackendHooks(lg, ci),
}
defer srv.r.raftNodeConfig.Stop()

// create EntryConfChange entry
now := time.Now()
Expand Down Expand Up @@ -547,6 +550,7 @@ func TestApplyMultiConfChangeShouldStop(t *testing.T) {
cl := membership.NewCluster(lg)
cl.SetStore(v2store.New())
be, _ := betesting.NewDefaultTmpBackend(t)
defer betesting.Close(t, be)
cl.SetBackend(schema.NewMembershipBackend(lg, be))

for i := 1; i <= 5; i++ {
Expand Down Expand Up @@ -596,6 +600,7 @@ func TestSnapshot(t *testing.T) {
defer revertFunc()

be, _ := betesting.NewDefaultTmpBackend(t)
defer betesting.Close(t, be)

s := raft.NewMemoryStorage()
s.Append([]raftpb.Entry{{Index: 1}})
Expand All @@ -615,6 +620,9 @@ func TestSnapshot(t *testing.T) {
consistIndex: cindex.NewConsistentIndex(be),
}
srv.kv = mvcc.New(zaptest.NewLogger(t), be, &lease.FakeLessor{}, mvcc.StoreConfig{})
defer func() {
assert.NoError(t, srv.kv.Close())
}()
srv.be = be

cl := membership.NewCluster(zaptest.NewLogger(t))
Expand Down Expand Up @@ -921,6 +929,7 @@ func TestProcessIgnoreMismatchMessage(t *testing.T) {
},
},
})
defer r.raftNodeConfig.Stop()
s := &EtcdServer{
lgMu: new(sync.RWMutex),
lg: lg,
Expand Down Expand Up @@ -961,6 +970,7 @@ func TestRemoveMember(t *testing.T) {
st := v2store.New()
cl.SetStore(v2store.New())
be, _ := betesting.NewDefaultTmpBackend(t)
defer betesting.Close(t, be)
cl.SetBackend(schema.NewMembershipBackend(lg, be))

cl.AddMember(&membership.Member{ID: 1234}, true)
Expand Down Expand Up @@ -1060,6 +1070,7 @@ func TestPublishV3(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
lg := zaptest.NewLogger(t)
be, _ := betesting.NewDefaultTmpBackend(t)
defer betesting.Close(t, be)
srv := &EtcdServer{
lgMu: new(sync.RWMutex),
lg: lg,
Expand Down Expand Up @@ -1130,6 +1141,7 @@ func TestPublishV3Retry(t *testing.T) {

lg := zaptest.NewLogger(t)
be, _ := betesting.NewDefaultTmpBackend(t)
defer betesting.Close(t, be)
srv := &EtcdServer{
lgMu: new(sync.RWMutex),
lg: lg,
Expand Down Expand Up @@ -1181,6 +1193,7 @@ func TestUpdateVersionV3(t *testing.T) {
ctx, cancel := context.WithCancel(context.TODO())
lg := zaptest.NewLogger(t)
be, _ := betesting.NewDefaultTmpBackend(t)
defer betesting.Close(t, be)
srv := &EtcdServer{
lgMu: new(sync.RWMutex),
lg: zaptest.NewLogger(t),
Expand Down

0 comments on commit 9281739

Please sign in to comment.