Merge pull request #116251 from wojtek-t/fix_ready_test

Fix deadlock in ready test
This commit is contained in:
Kubernetes Prow Robot 2023-03-03 10:25:19 -08:00 committed by GitHub
commit a1b12e49ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,7 @@ package cacher
import (
"context"
"sync"
"testing"
"time"
)
@ -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)