mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Fix race in RetryWatcher's unit tests
This commit is contained in:
parent
a514fa042e
commit
b39d079b69
@ -33,6 +33,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/apimachinery/pkg/util/diff"
|
"k8s.io/apimachinery/pkg/util/diff"
|
||||||
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
"k8s.io/client-go/tools/cache"
|
"k8s.io/client-go/tools/cache"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
@ -549,9 +550,17 @@ func TestRetryWatcher(t *testing.T) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
counter := atomic.LoadUint32(atomicCounter)
|
var counter uint32
|
||||||
if counter != tc.watchCount {
|
// 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)
|
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) {
|
if !reflect.DeepEqual(tc.expected, got) {
|
||||||
|
Loading…
Reference in New Issue
Block a user