mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-20 01:01:22 +00:00
cacher: decrease the running time of TestConsistentReadFallback
This commit is contained in:
parent
cfd6d9a2b4
commit
601c0e359d
@ -435,17 +435,15 @@ apiserver_watch_cache_consistent_read_total{fallback="true", resource="pods", su
|
|||||||
podList.ResourceVersion = tc.watchCacheRV
|
podList.ResourceVersion = tc.watchCacheRV
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// TODO: Use fake clock for this test to reduce execution time.
|
c := testingclock.NewFakeClock(time.Now())
|
||||||
cacher, _, err := newTestCacher(backingStorage)
|
cacher, _, err := newTestCacherWithoutSyncing(backingStorage, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Couldn't create cacher: %v", err)
|
t.Fatalf("Couldn't create cacher: %v", err)
|
||||||
}
|
}
|
||||||
defer cacher.Stop()
|
defer cacher.Stop()
|
||||||
proxy := NewCacheProxy(cacher, backingStorage)
|
proxy := NewCacheProxy(cacher, backingStorage)
|
||||||
if !utilfeature.DefaultFeatureGate.Enabled(features.ResilientWatchCacheInitialization) {
|
if err := cacher.ready.wait(context.Background()); err != nil {
|
||||||
if err := cacher.ready.wait(context.Background()); err != nil {
|
t.Fatalf("unexpected error waiting for the cache to be ready")
|
||||||
t.Fatalf("unexpected error waiting for the cache to be ready")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if fmt.Sprintf("%d", cacher.watchCache.resourceVersion) != tc.watchCacheRV {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
result := &example.PodList{}
|
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()
|
start := cacher.clock.Now()
|
||||||
err = proxy.GetList(context.TODO(), "pods/ns", storage.ListOptions{ResourceVersion: ""}, result)
|
err = proxy.GetList(context.TODO(), "pods/ns", storage.ListOptions{ResourceVersion: ""}, result)
|
||||||
|
clockStepCancelFn()
|
||||||
duration := cacher.clock.Since(start)
|
duration := cacher.clock.Since(start)
|
||||||
if (err != nil) != tc.expectError {
|
if (err != nil) != tc.expectError {
|
||||||
t.Fatalf("Unexpected error err: %v", err)
|
t.Fatalf("Unexpected error err: %v", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user