fix etcd unit tests
stop leaking goroutines reduce etcd test duration Kubernetes-commit: dd6d3d95cdeb0e165e8365212d85d0f3b972d3e8
This commit is contained in:
parent
fb26cb4f0c
commit
d2581bb0e0
|
@ -105,8 +105,10 @@ func TestCreateHealthcheck(t *testing.T) {
|
||||||
|
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
ready := make(chan struct{})
|
||||||
tc.cfg.Transport.ServerList = client.Endpoints()
|
tc.cfg.Transport.ServerList = client.Endpoints()
|
||||||
newETCD3Client = func(c storagebackend.TransportConfig) (*clientv3.Client, error) {
|
newETCD3Client = func(c storagebackend.TransportConfig) (*clientv3.Client, error) {
|
||||||
|
defer close(ready)
|
||||||
dummyKV := mockKV{
|
dummyKV := mockKV{
|
||||||
get: func(ctx context.Context) (*clientv3.GetResponse, error) {
|
get: func(ctx context.Context) (*clientv3.GetResponse, error) {
|
||||||
select {
|
select {
|
||||||
|
@ -121,13 +123,14 @@ func TestCreateHealthcheck(t *testing.T) {
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
stop := make(chan struct{})
|
stop := make(chan struct{})
|
||||||
|
defer close(stop)
|
||||||
|
|
||||||
healthcheck, err := CreateHealthCheck(tc.cfg, stop)
|
healthcheck, err := CreateHealthCheck(tc.cfg, stop)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
// Wait for healthcheck to establish connection
|
// Wait for healthcheck to establish connection
|
||||||
time.Sleep(2 * time.Second)
|
<-ready
|
||||||
|
|
||||||
got := healthcheck()
|
got := healthcheck()
|
||||||
|
|
||||||
if !errors.Is(got, tc.want) {
|
if !errors.Is(got, tc.want) {
|
||||||
|
@ -202,8 +205,10 @@ func TestCreateReadycheck(t *testing.T) {
|
||||||
|
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
ready := make(chan struct{})
|
||||||
tc.cfg.Transport.ServerList = client.Endpoints()
|
tc.cfg.Transport.ServerList = client.Endpoints()
|
||||||
newETCD3Client = func(c storagebackend.TransportConfig) (*clientv3.Client, error) {
|
newETCD3Client = func(c storagebackend.TransportConfig) (*clientv3.Client, error) {
|
||||||
|
defer close(ready)
|
||||||
dummyKV := mockKV{
|
dummyKV := mockKV{
|
||||||
get: func(ctx context.Context) (*clientv3.GetResponse, error) {
|
get: func(ctx context.Context) (*clientv3.GetResponse, error) {
|
||||||
select {
|
select {
|
||||||
|
@ -218,12 +223,14 @@ func TestCreateReadycheck(t *testing.T) {
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
stop := make(chan struct{})
|
stop := make(chan struct{})
|
||||||
|
defer close(stop)
|
||||||
|
|
||||||
healthcheck, err := CreateReadyCheck(tc.cfg, stop)
|
healthcheck, err := CreateReadyCheck(tc.cfg, stop)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
// Wait for healthcheck to establish connection
|
// Wait for healthcheck to establish connection
|
||||||
time.Sleep(2 * time.Second)
|
<-ready
|
||||||
|
|
||||||
got := healthcheck()
|
got := healthcheck()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue