mirror of https://github.com/k3s-io/k3s
Merge pull request #74663 from tnozicka/fix-retrywatcher-unit-flake
Fix race in RetryWatcher's unit testspull/564/head
commit
d11baea6f9
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue