Skip to content

Commit

Permalink
Fix deadlock in ready test
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtek-t authored and aojea committed Jul 3, 2023
1 parent 3a755bf commit 1159b79
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
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 1159b79

Please sign in to comment.