MCPcopy
hub / github.com/kubernetes/client-go / TestRetryWatcher

Function TestRetryWatcher

tools/watch/retrywatcher_test.go:170–571  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

168}
169
170func TestRetryWatcher(t *testing.T) {
171 tt := []struct {
172 name string
173 initialRV string
174 watchClient cache.Watcher
175 watchCount uint32
176 expected []watch.Event
177 }{
178 {
179 name: "recovers if watchClient returns error",
180 initialRV: "1",
181 watchClient: &cache.ListWatch{
182 WatchFunc: func() func(options metav1.ListOptions) (watch.Interface, error) {
183 firstRun := true
184 return func(options metav1.ListOptions) (watch.Interface, error) {
185 if firstRun {
186 firstRun = false
187 return nil, fmt.Errorf("test error")
188 }
189
190 return watch.NewProxyWatcher(arrayToChannel(fromRV(options.ResourceVersion, []watch.Event{
191 makeTestEvent(2),
192 }))), nil
193 }
194 }(),
195 },
196 watchCount: 2,
197 expected: []watch.Event{
198 makeTestEvent(2),
199 },
200 },
201 {
202 name: "recovers if watchClient returns nil watcher",
203 initialRV: "1",
204 watchClient: &cache.ListWatch{
205 WatchFunc: func() func(options metav1.ListOptions) (watch.Interface, error) {
206 firstRun := true
207 return func(options metav1.ListOptions) (watch.Interface, error) {
208 if firstRun {
209 firstRun = false
210 return nil, nil
211 }
212
213 return watch.NewProxyWatcher(arrayToChannel(fromRV(options.ResourceVersion, []watch.Event{
214 makeTestEvent(2),
215 }))), nil
216 }
217 }(),
218 },
219 watchCount: 2,
220 expected: []watch.Event{
221 makeTestEvent(2),
222 },
223 },
224 {
225 name: "works with empty initialRV",
226 initialRV: "1",
227 watchClient: &cache.ListWatch{

Callers

nothing calls this directly

Calls 12

arrayToChannelFunction · 0.85
fromRVFunction · 0.85
makeTestEventFunction · 0.85
closeAfterNFunction · 0.85
withCounterFunction · 0.85
newRetryWatcherFunction · 0.85
ErrorfMethod · 0.65
RunMethod · 0.65
StopMethod · 0.65
DoneMethod · 0.65
ErrorMethod · 0.65
ResultChanMethod · 0.45

Tested by

no test coverage detected