cacher: decrease the running time of TestConsistentReadFallback
Kubernetes-commit: 601c0e359dc959bbfaf42c5d8a8a0a9a2175db74
This commit is contained in:
parent
8a149c9296
commit
23e8a6cc2f
|
@ -435,17 +435,15 @@ apiserver_watch_cache_consistent_read_total{fallback="true", resource="pods", su
|
|||
podList.ResourceVersion = tc.watchCacheRV
|
||||
return nil
|
||||
}
|
||||
// TODO: Use fake clock for this test to reduce execution time.
|
||||
cacher, _, err := newTestCacher(backingStorage)
|
||||
c := testingclock.NewFakeClock(time.Now())
|
||||
cacher, _, err := newTestCacherWithoutSyncing(backingStorage, c)
|
||||
if err != nil {
|
||||
t.Fatalf("Couldn't create cacher: %v", err)
|
||||
}
|
||||
defer cacher.Stop()
|
||||
proxy := NewCacheProxy(cacher, backingStorage)
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.ResilientWatchCacheInitialization) {
|
||||
if err := cacher.ready.wait(context.Background()); err != nil {
|
||||
t.Fatalf("unexpected error waiting for the cache to be ready")
|
||||
}
|
||||
if err := cacher.ready.wait(context.Background()); err != nil {
|
||||
t.Fatalf("unexpected error waiting for the cache to be ready")
|
||||
}
|
||||
|
||||
if fmt.Sprintf("%d", cacher.watchCache.resourceVersion) != tc.watchCacheRV {
|
||||
|
@ -466,8 +464,28 @@ apiserver_watch_cache_consistent_read_total{fallback="true", resource="pods", su
|
|||
return nil
|
||||
}
|
||||
result := &example.PodList{}
|
||||
|
||||
ctx, clockStepCancelFn := context.WithTimeout(context.TODO(), time.Minute)
|
||||
defer clockStepCancelFn()
|
||||
if tc.expectBlock {
|
||||
go func(ctx context.Context) {
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
default:
|
||||
if c.HasWaiters() {
|
||||
c.Step(blockTimeout)
|
||||
}
|
||||
time.Sleep(time.Millisecond)
|
||||
}
|
||||
}
|
||||
}(ctx)
|
||||
}
|
||||
|
||||
start := cacher.clock.Now()
|
||||
err = proxy.GetList(context.TODO(), "pods/ns", storage.ListOptions{ResourceVersion: ""}, result)
|
||||
clockStepCancelFn()
|
||||
duration := cacher.clock.Since(start)
|
||||
if (err != nil) != tc.expectError {
|
||||
t.Fatalf("Unexpected error err: %v", err)
|
||||
|
|
Loading…
Reference in New Issue