@@ -435,17 +435,15 @@ apiserver_watch_cache_consistent_read_total{fallback="true", resource="pods", su
435
435
podList .ResourceVersion = tc .watchCacheRV
436
436
return nil
437
437
}
438
- // TODO: Use fake clock for this test to reduce execution time.
439
- cacher , _ , err := newTestCacher (backingStorage )
438
+ c := testingclock . NewFakeClock ( time .Now ())
439
+ cacher , _ , err := newTestCacherWithoutSyncing (backingStorage , c )
440
440
if err != nil {
441
441
t .Fatalf ("Couldn't create cacher: %v" , err )
442
442
}
443
443
defer cacher .Stop ()
444
444
proxy := NewCacheProxy (cacher , backingStorage )
445
- if ! utilfeature .DefaultFeatureGate .Enabled (features .ResilientWatchCacheInitialization ) {
446
- if err := cacher .ready .wait (context .Background ()); err != nil {
447
- t .Fatalf ("unexpected error waiting for the cache to be ready" )
448
- }
445
+ if err := cacher .ready .wait (context .Background ()); err != nil {
446
+ t .Fatalf ("unexpected error waiting for the cache to be ready" )
449
447
}
450
448
451
449
if fmt .Sprintf ("%d" , cacher .watchCache .resourceVersion ) != tc .watchCacheRV {
@@ -466,8 +464,28 @@ apiserver_watch_cache_consistent_read_total{fallback="true", resource="pods", su
466
464
return nil
467
465
}
468
466
result := & example.PodList {}
467
+
468
+ ctx , clockStepCancelFn := context .WithTimeout (context .TODO (), time .Minute )
469
+ defer clockStepCancelFn ()
470
+ if tc .expectBlock {
471
+ go func (ctx context.Context ) {
472
+ for {
473
+ select {
474
+ case <- ctx .Done ():
475
+ return
476
+ default :
477
+ if c .HasWaiters () {
478
+ c .Step (blockTimeout )
479
+ }
480
+ time .Sleep (time .Millisecond )
481
+ }
482
+ }
483
+ }(ctx )
484
+ }
485
+
469
486
start := cacher .clock .Now ()
470
487
err = proxy .GetList (context .TODO (), "pods/ns" , storage.ListOptions {ResourceVersion : "" }, result )
488
+ clockStepCancelFn ()
471
489
duration := cacher .clock .Since (start )
472
490
if (err != nil ) != tc .expectError {
473
491
t .Fatalf ("Unexpected error err: %v" , err )
0 commit comments