From d2581bb0e0a6bd26458cd390c1fa7ad98abe98f6 Mon Sep 17 00:00:00 2001 From: Antonio Ojea Date: Sun, 28 Aug 2022 23:13:45 +0200 Subject: [PATCH] fix etcd unit tests stop leaking goroutines reduce etcd test duration Kubernetes-commit: dd6d3d95cdeb0e165e8365212d85d0f3b972d3e8 --- pkg/storage/storagebackend/factory/factory_test.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/storage/storagebackend/factory/factory_test.go b/pkg/storage/storagebackend/factory/factory_test.go index 963d24c91..36fe8116f 100644 --- a/pkg/storage/storagebackend/factory/factory_test.go +++ b/pkg/storage/storagebackend/factory/factory_test.go @@ -105,8 +105,10 @@ func TestCreateHealthcheck(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { + ready := make(chan struct{}) tc.cfg.Transport.ServerList = client.Endpoints() newETCD3Client = func(c storagebackend.TransportConfig) (*clientv3.Client, error) { + defer close(ready) dummyKV := mockKV{ get: func(ctx context.Context) (*clientv3.GetResponse, error) { select { @@ -121,13 +123,14 @@ func TestCreateHealthcheck(t *testing.T) { return client, nil } stop := make(chan struct{}) + defer close(stop) + healthcheck, err := CreateHealthCheck(tc.cfg, stop) if err != nil { t.Fatal(err) } // Wait for healthcheck to establish connection - time.Sleep(2 * time.Second) - + <-ready got := healthcheck() if !errors.Is(got, tc.want) { @@ -202,8 +205,10 @@ func TestCreateReadycheck(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { + ready := make(chan struct{}) tc.cfg.Transport.ServerList = client.Endpoints() newETCD3Client = func(c storagebackend.TransportConfig) (*clientv3.Client, error) { + defer close(ready) dummyKV := mockKV{ get: func(ctx context.Context) (*clientv3.GetResponse, error) { select { @@ -218,12 +223,14 @@ func TestCreateReadycheck(t *testing.T) { return client, nil } stop := make(chan struct{}) + defer close(stop) + healthcheck, err := CreateReadyCheck(tc.cfg, stop) if err != nil { t.Fatal(err) } // Wait for healthcheck to establish connection - time.Sleep(2 * time.Second) + <-ready got := healthcheck()