@@ -216,7 +216,7 @@ func (d *dummyCacher) Ready() bool {
216
216
return d .ready
217
217
}
218
218
219
- func TestGetListCacheBypass (t * testing.T ) {
219
+ func TestShouldDelegateList (t * testing.T ) {
220
220
type opts struct {
221
221
Recursive bool
222
222
ResourceVersion string
@@ -324,7 +324,10 @@ func TestGetListCacheBypass(t *testing.T) {
324
324
expectBypass = bypass
325
325
}
326
326
}
327
- testGetListCacheBypass (t , toStorageOpts (opt ), expectBypass )
327
+ gotBypass , _ := shouldDelegateList (toStorageOpts (opt ))
328
+ if gotBypass != expectBypass {
329
+ t .Errorf ("Unexpected bypass result for List request with options %+v, bypass expected: %v, got: %v" , opt , expectBypass , gotBypass )
330
+ }
328
331
}
329
332
}
330
333
consistentListFromCacheOverrides := map [opts ]bool {}
@@ -351,49 +354,6 @@ func TestGetListCacheBypass(t *testing.T) {
351
354
})
352
355
}
353
356
354
- func testGetListCacheBypass (t * testing.T , options storage.ListOptions , expectBypass bool ) {
355
- backingStorage := & dummyStorage {}
356
- cacher , _ , err := newTestCacher (backingStorage )
357
- if err != nil {
358
- t .Fatalf ("Couldn't create cacher: %v" , err )
359
- }
360
- defer cacher .Stop ()
361
- delegator := NewCacheDelegator (cacher , backingStorage )
362
- defer delegator .Stop ()
363
- result := & example.PodList {}
364
- if ! utilfeature .DefaultFeatureGate .Enabled (features .ResilientWatchCacheInitialization ) {
365
- if err := cacher .ready .wait (context .Background ()); err != nil {
366
- t .Fatalf ("unexpected error waiting for the cache to be ready" )
367
- }
368
- }
369
- // Inject error to underlying layer and check if cacher is not bypassed.
370
- backingStorage .getListFn = func (_ context.Context , key string , opts storage.ListOptions , listObj runtime.Object ) error {
371
- currentResourceVersion := "42"
372
- switch {
373
- // request made by getCurrentResourceVersionFromStorage by checking Limit
374
- case key == cacher .resourcePrefix :
375
- podList := listObj .(* example.PodList )
376
- podList .ResourceVersion = currentResourceVersion
377
- return nil
378
- // request made by storage.GetList with revision from original request or
379
- // returned by getCurrentResourceVersionFromStorage
380
- case opts .ResourceVersion == options .ResourceVersion || opts .ResourceVersion == currentResourceVersion :
381
- return errDummy
382
- default :
383
- t .Fatalf ("Unexpected request %+v" , opts )
384
- return nil
385
- }
386
- }
387
- err = delegator .GetList (context .TODO (), "pods/ns" , options , result )
388
- gotBypass := errors .Is (err , errDummy )
389
- if err != nil && ! gotBypass {
390
- t .Fatalf ("Unexpected error for List request with options: %v, err: %v" , options , err )
391
- }
392
- if gotBypass != expectBypass {
393
- t .Errorf ("Unexpected bypass result for List request with options %+v, bypass expected: %v, got: %v" , options , expectBypass , gotBypass )
394
- }
395
- }
396
-
397
357
func TestConsistentReadFallback (t * testing.T ) {
398
358
tcs := []struct {
399
359
name string
0 commit comments