Skip to content

Commit

Permalink
Merge pull request #119031 from aojea/automated-cherry-pick-of-#11625…
Browse files Browse the repository at this point in the history
…1-upstream-release-1.25

Automated cherry pick of #116251: Fix deadlock in ready test
  • Loading branch information
k8s-ci-robot committed Jul 6, 2023
2 parents 3a755bf + 1159b79 commit 69482fd
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions staging/src/k8s.io/apiserver/pkg/storage/cacher/ready_test.go
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 69482fd

Please sign in to comment.