Skip to content

Commit

Permalink
Fix deadlock in ready test
Browse files Browse the repository at this point in the history
Kubernetes-commit: 07ba40eaa7a13ccf8be4b1d9075a64ff759b300f
  • Loading branch information
wojtek-t authored and k8s-publishing-bot committed Mar 3, 2023
1 parent de6c847 commit 01571a2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/storage/cacher/ready_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cacher

import (
"context"
"sync"
"testing"
"time"
)
Expand Down Expand Up @@ -81,18 +82,26 @@ func Test_newReadyRacy(t *testing.T) {
errCh := make(chan error, concurrency)
ready := newReady()
ready.set(false)

wg := sync.WaitGroup{}
wg.Add(2 * concurrency)
for i := 0; i < concurrency; i++ {
go func() {
errCh <- ready.wait(context.Background())
}()
go func() {
defer wg.Done()
ready.set(false)
}()
go func() {
defer wg.Done()
ready.set(true)
}()
}
// Last one has to be set to true.
wg.Wait()
ready.set(true)

for i := 0; i < concurrency; i++ {
if err := <-errCh; err != nil {
t.Errorf("unexpected error %v on channel %d", err, i)
Expand Down

0 comments on commit 01571a2

Please sign in to comment.