Merge pull request #74663 from tnozicka/fix-retrywatcher-unit-flake

Fix race in RetryWatcher's unit tests
pull/564/head
Kubernetes Prow Robot 2019-02-27 11:13:30 -08:00 committed by GitHub
commit d11baea6f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 2 deletions

View File

@ -33,6 +33,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"
"k8s.io/klog"
@ -549,9 +550,17 @@ func TestRetryWatcher(t *testing.T) {
break
}
counter := atomic.LoadUint32(atomicCounter)
if counter != tc.watchCount {
var counter uint32
// We always count with the last watch reestablishing which is imminent but still a race.
// We will wait for the last watch to reestablish to avoid it.
err = wait.PollImmediate(10*time.Millisecond, 10*time.Second, func() (done bool, err error) {
counter = atomic.LoadUint32(atomicCounter)
return counter == tc.watchCount, nil
})
if err == wait.ErrWaitTimeout {
t.Errorf("expected %d watcher starts, but it has started %d times", tc.watchCount, counter)
} else if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(tc.expected, got) {