mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-23 05:37:13 +00:00
Merge pull request #124642 from wojtek-t/resilient_watchcache_initialization
Implement ResilientWatchCacheInitialization Kubernetes-commit: eef6c6082d4e34fc4a0675a36ec5cc575cd13696
This commit is contained in:
commit
1c075dc88c
48
tools/cache/reflector_test.go
vendored
48
tools/cache/reflector_test.go
vendored
@ -697,13 +697,59 @@ func TestBackoffOnTooManyRequests(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stopCh := make(chan struct{})
|
stopCh := make(chan struct{})
|
||||||
r.ListAndWatch(stopCh)
|
if err := r.ListAndWatch(stopCh); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
close(stopCh)
|
close(stopCh)
|
||||||
if bm.calls != 2 {
|
if bm.calls != 2 {
|
||||||
t.Errorf("unexpected watch backoff calls: %d", bm.calls)
|
t.Errorf("unexpected watch backoff calls: %d", bm.calls)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNoRelistOnTooManyRequests(t *testing.T) {
|
||||||
|
err := apierrors.NewTooManyRequests("too many requests", 1)
|
||||||
|
clock := &clock.RealClock{}
|
||||||
|
bm := &fakeBackoff{clock: clock}
|
||||||
|
listCalls, watchCalls := 0, 0
|
||||||
|
|
||||||
|
lw := &testLW{
|
||||||
|
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
||||||
|
listCalls++
|
||||||
|
return &v1.PodList{ListMeta: metav1.ListMeta{ResourceVersion: "1"}}, nil
|
||||||
|
},
|
||||||
|
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
|
||||||
|
watchCalls++
|
||||||
|
if watchCalls < 5 {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
w := watch.NewFake()
|
||||||
|
w.Stop()
|
||||||
|
return w, nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
r := &Reflector{
|
||||||
|
name: "test-reflector",
|
||||||
|
listerWatcher: lw,
|
||||||
|
store: NewFIFO(MetaNamespaceKeyFunc),
|
||||||
|
backoffManager: bm,
|
||||||
|
clock: clock,
|
||||||
|
watchErrorHandler: WatchErrorHandler(DefaultWatchErrorHandler),
|
||||||
|
}
|
||||||
|
|
||||||
|
stopCh := make(chan struct{})
|
||||||
|
if err := r.ListAndWatch(stopCh); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
close(stopCh)
|
||||||
|
if listCalls != 1 {
|
||||||
|
t.Errorf("unexpected list calls: %d", listCalls)
|
||||||
|
}
|
||||||
|
if watchCalls != 5 {
|
||||||
|
t.Errorf("unexpected watch calls: %d", watchCalls)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestRetryInternalError(t *testing.T) {
|
func TestRetryInternalError(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
|
Loading…
Reference in New Issue
Block a user