diff --git a/staging/src/k8s.io/apiserver/pkg/storage/etcd3/store_test.go b/staging/src/k8s.io/apiserver/pkg/storage/etcd3/store_test.go index 9c7a0c41088..ef7bf2cc3b6 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/etcd3/store_test.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/etcd3/store_test.go @@ -1035,7 +1035,7 @@ func TestGuaranteedUpdateWithSuggestionAndConflict(t *testing.T) { func TestTransformationFailure(t *testing.T) { client := testserver.RunEtcd(t, nil) codec := apitesting.TestCodec(codecs, examplev1.SchemeGroupVersion) - store := newStore(client, codec, newPod, "", schema.GroupResource{Resource: "pods"}, &prefixTransformer{prefix: []byte(defaultTestPrefix)}, false, NewDefaultLeaseManagerConfig()) + store := newStore(client, codec, newPod, "", schema.GroupResource{Resource: "pods"}, &prefixTransformer{prefix: []byte(defaultTestPrefix)}, false, newTestLeaseManagerConfig()) ctx := context.Background() preset := []struct { @@ -1115,8 +1115,8 @@ func TestList(t *testing.T) { client := testserver.RunEtcd(t, nil) defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.RemainingItemCount, true)() codec := apitesting.TestCodec(codecs, examplev1.SchemeGroupVersion) - store := newStore(client, codec, newPod, "", schema.GroupResource{Resource: "pods"}, &prefixTransformer{prefix: []byte(defaultTestPrefix)}, true, NewDefaultLeaseManagerConfig()) - disablePagingStore := newStore(client, codec, newPod, "", schema.GroupResource{Resource: "pods"}, &prefixTransformer{prefix: []byte(defaultTestPrefix)}, false, NewDefaultLeaseManagerConfig()) + store := newStore(client, codec, newPod, "", schema.GroupResource{Resource: "pods"}, &prefixTransformer{prefix: []byte(defaultTestPrefix)}, true, newTestLeaseManagerConfig()) + disablePagingStore := newStore(client, codec, newPod, "", schema.GroupResource{Resource: "pods"}, &prefixTransformer{prefix: []byte(defaultTestPrefix)}, false, newTestLeaseManagerConfig()) ctx := context.Background() // Setup storage with the following structure: @@ -1631,7 +1631,7 @@ func TestListContinuation(t *testing.T) { transformer := &prefixTransformer{prefix: []byte(defaultTestPrefix)} recorder := &clientRecorder{KV: etcdClient.KV} etcdClient.KV = recorder - store := newStore(etcdClient, codec, newPod, "", schema.GroupResource{Resource: "pods"}, transformer, true, NewDefaultLeaseManagerConfig()) + store := newStore(etcdClient, codec, newPod, "", schema.GroupResource{Resource: "pods"}, transformer, true, newTestLeaseManagerConfig()) ctx := context.Background() // Setup storage with the following structure: @@ -1803,7 +1803,7 @@ func TestListContinuationWithFilter(t *testing.T) { transformer := &prefixTransformer{prefix: []byte(defaultTestPrefix)} recorder := &clientRecorder{KV: etcdClient.KV} etcdClient.KV = recorder - store := newStore(etcdClient, codec, newPod, "", schema.GroupResource{Resource: "pods"}, transformer, true, NewDefaultLeaseManagerConfig()) + store := newStore(etcdClient, codec, newPod, "", schema.GroupResource{Resource: "pods"}, transformer, true, newTestLeaseManagerConfig()) ctx := context.Background() preset := []struct { @@ -1911,7 +1911,7 @@ func TestListContinuationWithFilter(t *testing.T) { func TestListInconsistentContinuation(t *testing.T) { client := testserver.RunEtcd(t, nil) codec := apitesting.TestCodec(codecs, examplev1.SchemeGroupVersion) - store := newStore(client, codec, newPod, "", schema.GroupResource{Resource: "pods"}, &prefixTransformer{prefix: []byte(defaultTestPrefix)}, true, NewDefaultLeaseManagerConfig()) + store := newStore(client, codec, newPod, "", schema.GroupResource{Resource: "pods"}, &prefixTransformer{prefix: []byte(defaultTestPrefix)}, true, newTestLeaseManagerConfig()) ctx := context.Background() // Setup storage with the following structure: @@ -2067,16 +2067,19 @@ func TestListInconsistentContinuation(t *testing.T) { } } +func newTestLeaseManagerConfig() LeaseManagerConfig { + cfg := NewDefaultLeaseManagerConfig() + // As 30s is the default timeout for testing in global configuration, + // we cannot wait longer than that in a single time: change it to 1s + // for testing purposes. See wait.ForeverTestTimeout + cfg.ReuseDurationSeconds = 1 + return cfg +} + func testSetup(t *testing.T) (context.Context, *store, *clientv3.Client) { client := testserver.RunEtcd(t, nil) codec := apitesting.TestCodec(codecs, examplev1.SchemeGroupVersion) - // As 30s is the default timeout for testing in glboal configuration, - // we cannot wait longer than that in a single time: change it to 10 - // for testing purposes. See apimachinery/pkg/util/wait/wait.go - store := newStore(client, codec, newPod, "", schema.GroupResource{Resource: "pods"}, &prefixTransformer{prefix: []byte(defaultTestPrefix)}, true, LeaseManagerConfig{ - ReuseDurationSeconds: 1, - MaxObjectCount: defaultLeaseMaxObjectCount, - }) + store := newStore(client, codec, newPod, "", schema.GroupResource{Resource: "pods"}, &prefixTransformer{prefix: []byte(defaultTestPrefix)}, true, newTestLeaseManagerConfig()) ctx := context.Background() return ctx, store, client } @@ -2117,7 +2120,7 @@ func TestPrefix(t *testing.T) { "/registry": "/registry", } for configuredPrefix, effectivePrefix := range testcases { - store := newStore(client, codec, nil, configuredPrefix, schema.GroupResource{Resource: "widgets"}, transformer, true, NewDefaultLeaseManagerConfig()) + store := newStore(client, codec, nil, configuredPrefix, schema.GroupResource{Resource: "widgets"}, transformer, true, newTestLeaseManagerConfig()) if store.pathPrefix != effectivePrefix { t.Errorf("configured prefix of %s, expected effective prefix of %s, got %s", configuredPrefix, effectivePrefix, store.pathPrefix) } @@ -2283,7 +2286,7 @@ func TestConsistentList(t *testing.T) { transformer := &fancyTransformer{ transformer: &prefixTransformer{prefix: []byte(defaultTestPrefix)}, } - store := newStore(client, codec, newPod, "", schema.GroupResource{Resource: "pods"}, transformer, true, NewDefaultLeaseManagerConfig()) + store := newStore(client, codec, newPod, "", schema.GroupResource{Resource: "pods"}, transformer, true, newTestLeaseManagerConfig()) transformer.store = store for i := 0; i < 5; i++ { diff --git a/staging/src/k8s.io/apiserver/pkg/storage/etcd3/watcher_test.go b/staging/src/k8s.io/apiserver/pkg/storage/etcd3/watcher_test.go index 3c96587c97e..6f0fe95103c 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/etcd3/watcher_test.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/etcd3/watcher_test.go @@ -226,14 +226,14 @@ func TestWatchError(t *testing.T) { // this codec fails on decodes, which will bubble up so we can verify the behavior invalidCodec := &testCodec{apitesting.TestCodec(codecs, examplev1.SchemeGroupVersion)} client := testserver.RunEtcd(t, nil) - invalidStore := newStore(client, invalidCodec, newPod, "", schema.GroupResource{Resource: "pods"}, &prefixTransformer{prefix: []byte("test!")}, true, NewDefaultLeaseManagerConfig()) + invalidStore := newStore(client, invalidCodec, newPod, "", schema.GroupResource{Resource: "pods"}, &prefixTransformer{prefix: []byte("test!")}, true, newTestLeaseManagerConfig()) ctx := context.Background() w, err := invalidStore.Watch(ctx, "/abc", storage.ListOptions{ResourceVersion: "0", Predicate: storage.Everything}) if err != nil { t.Fatalf("Watch failed: %v", err) } codec := apitesting.TestCodec(codecs, examplev1.SchemeGroupVersion) - validStore := newStore(client, codec, newPod, "", schema.GroupResource{Resource: "pods"}, &prefixTransformer{prefix: []byte("test!")}, true, NewDefaultLeaseManagerConfig()) + validStore := newStore(client, codec, newPod, "", schema.GroupResource{Resource: "pods"}, &prefixTransformer{prefix: []byte("test!")}, true, newTestLeaseManagerConfig()) if err := validStore.GuaranteedUpdate(ctx, "/abc", &example.Pod{}, true, nil, storage.SimpleUpdate( func(runtime.Object) (runtime.Object, error) { return &example.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}, nil @@ -335,7 +335,7 @@ func TestProgressNotify(t *testing.T) { clusterConfig := testserver.NewTestConfig(t) clusterConfig.ExperimentalWatchProgressNotifyInterval = time.Second client := testserver.RunEtcd(t, clusterConfig) - store := newStore(client, codec, newPod, "", schema.GroupResource{Resource: "pods"}, &prefixTransformer{prefix: []byte(defaultTestPrefix)}, false, NewDefaultLeaseManagerConfig()) + store := newStore(client, codec, newPod, "", schema.GroupResource{Resource: "pods"}, &prefixTransformer{prefix: []byte(defaultTestPrefix)}, false, newTestLeaseManagerConfig()) ctx := context.Background() key := "/somekey"