mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
Slightly improve reliability of storage List tests.
This commit is contained in:
parent
7c013c3f64
commit
8ca6c5922b
@ -343,7 +343,11 @@ func (e *Store) ListPredicate(ctx context.Context, p storage.SelectionPredicate,
|
|||||||
p.Continue = options.Continue
|
p.Continue = options.Continue
|
||||||
list := e.NewListFunc()
|
list := e.NewListFunc()
|
||||||
qualifiedResource := e.qualifiedResourceFromContext(ctx)
|
qualifiedResource := e.qualifiedResourceFromContext(ctx)
|
||||||
storageOpts := storage.ListOptions{ResourceVersion: options.ResourceVersion, ResourceVersionMatch: options.ResourceVersionMatch, Predicate: p}
|
storageOpts := storage.ListOptions{
|
||||||
|
ResourceVersion: options.ResourceVersion,
|
||||||
|
ResourceVersionMatch: options.ResourceVersionMatch,
|
||||||
|
Predicate: p,
|
||||||
|
}
|
||||||
if name, ok := p.MatchesSingle(); ok {
|
if name, ok := p.MatchesSingle(); ok {
|
||||||
if key, err := e.KeyFunc(ctx, name); err == nil {
|
if key, err := e.KeyFunc(ctx, name); err == nil {
|
||||||
err := e.Storage.GetToList(ctx, key, storageOpts, list)
|
err := e.Storage.GetToList(ctx, key, storageOpts, list)
|
||||||
|
@ -1087,7 +1087,11 @@ func (lw *cacherListerWatcher) List(options metav1.ListOptions) (runtime.Object,
|
|||||||
Continue: options.Continue,
|
Continue: options.Continue,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := lw.storage.List(context.TODO(), lw.resourcePrefix, storage.ListOptions{ResourceVersionMatch: options.ResourceVersionMatch, Predicate: pred}, list); err != nil {
|
storageOpts := storage.ListOptions{
|
||||||
|
ResourceVersionMatch: options.ResourceVersionMatch,
|
||||||
|
Predicate: pred,
|
||||||
|
}
|
||||||
|
if err := lw.storage.List(context.TODO(), lw.resourcePrefix, storageOpts, list); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return list, nil
|
return list, nil
|
||||||
|
@ -1043,7 +1043,10 @@ func TestTransformationFailure(t *testing.T) {
|
|||||||
|
|
||||||
// List should fail
|
// List should fail
|
||||||
var got example.PodList
|
var got example.PodList
|
||||||
if err := store.List(ctx, "/", storage.ListOptions{Predicate: storage.Everything}, &got); !storage.IsInternalError(err) {
|
storageOpts := storage.ListOptions{
|
||||||
|
Predicate: storage.Everything,
|
||||||
|
}
|
||||||
|
if err := store.List(ctx, "/", storageOpts, &got); !storage.IsInternalError(err) {
|
||||||
t.Errorf("Unexpected error %v", err)
|
t.Errorf("Unexpected error %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1135,7 +1138,13 @@ func TestList(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
list := &example.PodList{}
|
list := &example.PodList{}
|
||||||
store.List(ctx, "/two-level", storage.ListOptions{ResourceVersion: "0", Predicate: storage.Everything}, list)
|
storageOpts := storage.ListOptions{
|
||||||
|
ResourceVersion: "0",
|
||||||
|
Predicate: storage.Everything,
|
||||||
|
}
|
||||||
|
if err := store.List(ctx, "/two-level", storageOpts, list); err != nil {
|
||||||
|
t.Errorf("Unexpected List error: %v", err)
|
||||||
|
}
|
||||||
continueRV, _ := strconv.Atoi(list.ResourceVersion)
|
continueRV, _ := strconv.Atoi(list.ResourceVersion)
|
||||||
secondContinuation, err := encodeContinue("/two-level/2", "/two-level/", int64(continueRV))
|
secondContinuation, err := encodeContinue("/two-level/2", "/two-level/", int64(continueRV))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1519,7 +1528,11 @@ func TestList(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
out := &example.PodList{}
|
out := &example.PodList{}
|
||||||
storageOpts := storage.ListOptions{ResourceVersion: tt.rv, ResourceVersionMatch: tt.rvMatch, Predicate: tt.pred}
|
storageOpts := storage.ListOptions{
|
||||||
|
ResourceVersion: tt.rv,
|
||||||
|
ResourceVersionMatch: tt.rvMatch,
|
||||||
|
Predicate: tt.pred,
|
||||||
|
}
|
||||||
var err error
|
var err error
|
||||||
if tt.disablePaging {
|
if tt.disablePaging {
|
||||||
err = disablePagingStore.List(ctx, tt.prefix, storageOpts, out)
|
err = disablePagingStore.List(ctx, tt.prefix, storageOpts, out)
|
||||||
@ -1630,7 +1643,11 @@ func TestListContinuation(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := store.List(ctx, "/", storage.ListOptions{ResourceVersion: "0", Predicate: pred(1, "")}, out); err != nil {
|
options := storage.ListOptions{
|
||||||
|
ResourceVersion: "0",
|
||||||
|
Predicate: pred(1, ""),
|
||||||
|
}
|
||||||
|
if err := store.List(ctx, "/", options, out); err != nil {
|
||||||
t.Fatalf("Unable to get initial list: %v", err)
|
t.Fatalf("Unable to get initial list: %v", err)
|
||||||
}
|
}
|
||||||
if len(out.Continue) == 0 {
|
if len(out.Continue) == 0 {
|
||||||
@ -1652,7 +1669,11 @@ func TestListContinuation(t *testing.T) {
|
|||||||
|
|
||||||
// no limit, should get two items
|
// no limit, should get two items
|
||||||
out = &example.PodList{}
|
out = &example.PodList{}
|
||||||
if err := store.List(ctx, "/", storage.ListOptions{ResourceVersion: "0", Predicate: pred(0, continueFromSecondItem)}, out); err != nil {
|
options = storage.ListOptions{
|
||||||
|
ResourceVersion: "0",
|
||||||
|
Predicate: pred(0, continueFromSecondItem),
|
||||||
|
}
|
||||||
|
if err := store.List(ctx, "/", options, out); err != nil {
|
||||||
t.Fatalf("Unable to get second page: %v", err)
|
t.Fatalf("Unable to get second page: %v", err)
|
||||||
}
|
}
|
||||||
if len(out.Continue) != 0 {
|
if len(out.Continue) != 0 {
|
||||||
@ -1674,7 +1695,11 @@ func TestListContinuation(t *testing.T) {
|
|||||||
|
|
||||||
// limit, should get two more pages
|
// limit, should get two more pages
|
||||||
out = &example.PodList{}
|
out = &example.PodList{}
|
||||||
if err := store.List(ctx, "/", storage.ListOptions{ResourceVersion: "0", Predicate: pred(1, continueFromSecondItem)}, out); err != nil {
|
options = storage.ListOptions{
|
||||||
|
ResourceVersion: "0",
|
||||||
|
Predicate: pred(1, continueFromSecondItem),
|
||||||
|
}
|
||||||
|
if err := store.List(ctx, "/", options, out); err != nil {
|
||||||
t.Fatalf("Unable to get second page: %v", err)
|
t.Fatalf("Unable to get second page: %v", err)
|
||||||
}
|
}
|
||||||
if len(out.Continue) == 0 {
|
if len(out.Continue) == 0 {
|
||||||
@ -1695,7 +1720,11 @@ func TestListContinuation(t *testing.T) {
|
|||||||
continueFromThirdItem := out.Continue
|
continueFromThirdItem := out.Continue
|
||||||
|
|
||||||
out = &example.PodList{}
|
out = &example.PodList{}
|
||||||
if err := store.List(ctx, "/", storage.ListOptions{ResourceVersion: "0", Predicate: pred(1, continueFromThirdItem)}, out); err != nil {
|
options = storage.ListOptions{
|
||||||
|
ResourceVersion: "0",
|
||||||
|
Predicate: pred(1, continueFromThirdItem),
|
||||||
|
}
|
||||||
|
if err := store.List(ctx, "/", options, out); err != nil {
|
||||||
t.Fatalf("Unable to get second page: %v", err)
|
t.Fatalf("Unable to get second page: %v", err)
|
||||||
}
|
}
|
||||||
if len(out.Continue) != 0 {
|
if len(out.Continue) != 0 {
|
||||||
@ -1785,7 +1814,11 @@ func TestListContinuationWithFilter(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := store.List(ctx, "/", storage.ListOptions{ResourceVersion: "0", Predicate: pred(2, "")}, out); err != nil {
|
options := storage.ListOptions{
|
||||||
|
ResourceVersion: "0",
|
||||||
|
Predicate: pred(2, ""),
|
||||||
|
}
|
||||||
|
if err := store.List(ctx, "/", options, out); err != nil {
|
||||||
t.Errorf("Unable to get initial list: %v", err)
|
t.Errorf("Unable to get initial list: %v", err)
|
||||||
}
|
}
|
||||||
if len(out.Continue) == 0 {
|
if len(out.Continue) == 0 {
|
||||||
@ -1814,7 +1847,11 @@ func TestListContinuationWithFilter(t *testing.T) {
|
|||||||
// but since there is only one item left, that is all we should get with no continueValue
|
// but since there is only one item left, that is all we should get with no continueValue
|
||||||
// both read counters should be incremented for the singular calls they make in this case
|
// both read counters should be incremented for the singular calls they make in this case
|
||||||
out = &example.PodList{}
|
out = &example.PodList{}
|
||||||
if err := store.List(ctx, "/", storage.ListOptions{ResourceVersion: "0", Predicate: pred(2, cont)}, out); err != nil {
|
options = storage.ListOptions{
|
||||||
|
ResourceVersion: "0",
|
||||||
|
Predicate: pred(2, cont),
|
||||||
|
}
|
||||||
|
if err := store.List(ctx, "/", options, out); err != nil {
|
||||||
t.Errorf("Unable to get second page: %v", err)
|
t.Errorf("Unable to get second page: %v", err)
|
||||||
}
|
}
|
||||||
if len(out.Continue) != 0 {
|
if len(out.Continue) != 0 {
|
||||||
@ -1892,7 +1929,11 @@ func TestListInconsistentContinuation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
out := &example.PodList{}
|
out := &example.PodList{}
|
||||||
if err := store.List(ctx, "/", storage.ListOptions{ResourceVersion: "0", Predicate: pred(1, "")}, out); err != nil {
|
options := storage.ListOptions{
|
||||||
|
ResourceVersion: "0",
|
||||||
|
Predicate: pred(1, ""),
|
||||||
|
}
|
||||||
|
if err := store.List(ctx, "/", options, out); err != nil {
|
||||||
t.Fatalf("Unable to get initial list: %v", err)
|
t.Fatalf("Unable to get initial list: %v", err)
|
||||||
}
|
}
|
||||||
if len(out.Continue) == 0 {
|
if len(out.Continue) == 0 {
|
||||||
@ -1933,7 +1974,11 @@ func TestListInconsistentContinuation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The old continue token should have expired
|
// The old continue token should have expired
|
||||||
err = store.List(ctx, "/", storage.ListOptions{ResourceVersion: "0", Predicate: pred(0, continueFromSecondItem)}, out)
|
options = storage.ListOptions{
|
||||||
|
ResourceVersion: "0",
|
||||||
|
Predicate: pred(0, continueFromSecondItem),
|
||||||
|
}
|
||||||
|
err = store.List(ctx, "/", options, out)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("unexpected no error")
|
t.Fatalf("unexpected no error")
|
||||||
}
|
}
|
||||||
@ -1950,7 +1995,11 @@ func TestListInconsistentContinuation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
out = &example.PodList{}
|
out = &example.PodList{}
|
||||||
if err := store.List(ctx, "/", storage.ListOptions{ResourceVersion: "0", Predicate: pred(1, inconsistentContinueFromSecondItem)}, out); err != nil {
|
options = storage.ListOptions{
|
||||||
|
ResourceVersion: "0",
|
||||||
|
Predicate: pred(1, inconsistentContinueFromSecondItem),
|
||||||
|
}
|
||||||
|
if err := store.List(ctx, "/", options, out); err != nil {
|
||||||
t.Fatalf("Unable to get second page: %v", err)
|
t.Fatalf("Unable to get second page: %v", err)
|
||||||
}
|
}
|
||||||
if len(out.Continue) == 0 {
|
if len(out.Continue) == 0 {
|
||||||
@ -1964,7 +2013,11 @@ func TestListInconsistentContinuation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
continueFromThirdItem := out.Continue
|
continueFromThirdItem := out.Continue
|
||||||
out = &example.PodList{}
|
out = &example.PodList{}
|
||||||
if err := store.List(ctx, "/", storage.ListOptions{ResourceVersion: "0", Predicate: pred(1, continueFromThirdItem)}, out); err != nil {
|
options = storage.ListOptions{
|
||||||
|
ResourceVersion: "0",
|
||||||
|
Predicate: pred(1, continueFromThirdItem),
|
||||||
|
}
|
||||||
|
if err := store.List(ctx, "/", options, out); err != nil {
|
||||||
t.Fatalf("Unable to get second page: %v", err)
|
t.Fatalf("Unable to get second page: %v", err)
|
||||||
}
|
}
|
||||||
if len(out.Continue) != 0 {
|
if len(out.Continue) != 0 {
|
||||||
@ -2216,12 +2269,15 @@ func TestConsistentList(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
result1 := example.PodList{}
|
result1 := example.PodList{}
|
||||||
if err := store.List(context.TODO(), "/", storage.ListOptions{Predicate: predicate}, &result1); err != nil {
|
options := storage.ListOptions{
|
||||||
|
Predicate: predicate,
|
||||||
|
}
|
||||||
|
if err := store.List(context.TODO(), "/", options, &result1); err != nil {
|
||||||
t.Fatalf("failed to list objects: %v", err)
|
t.Fatalf("failed to list objects: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// List objects from the returned resource version.
|
// List objects from the returned resource version.
|
||||||
options := storage.ListOptions{
|
options = storage.ListOptions{
|
||||||
Predicate: predicate,
|
Predicate: predicate,
|
||||||
ResourceVersion: result1.ResourceVersion,
|
ResourceVersion: result1.ResourceVersion,
|
||||||
ResourceVersionMatch: metav1.ResourceVersionMatchExact,
|
ResourceVersionMatch: metav1.ResourceVersionMatchExact,
|
||||||
|
@ -291,7 +291,10 @@ func TestList(t *testing.T) {
|
|||||||
// We first List directly from etcd by passing empty resourceVersion,
|
// We first List directly from etcd by passing empty resourceVersion,
|
||||||
// to get the current etcd resourceVersion.
|
// to get the current etcd resourceVersion.
|
||||||
rvResult := &example.PodList{}
|
rvResult := &example.PodList{}
|
||||||
if err := cacher.List(context.TODO(), "pods/ns", storage.ListOptions{Predicate: storage.Everything}, rvResult); err != nil {
|
options := storage.ListOptions{
|
||||||
|
Predicate: storage.Everything,
|
||||||
|
}
|
||||||
|
if err := cacher.List(context.TODO(), "pods/ns", options, rvResult); err != nil {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
deletedPodRV := rvResult.ListMeta.ResourceVersion
|
deletedPodRV := rvResult.ListMeta.ResourceVersion
|
||||||
@ -299,7 +302,11 @@ func TestList(t *testing.T) {
|
|||||||
result := &example.PodList{}
|
result := &example.PodList{}
|
||||||
// We pass the current etcd ResourceVersion received from the above List() operation,
|
// We pass the current etcd ResourceVersion received from the above List() operation,
|
||||||
// since there is not easy way to get ResourceVersion of barPod deletion operation.
|
// since there is not easy way to get ResourceVersion of barPod deletion operation.
|
||||||
if err := cacher.List(context.TODO(), "pods/ns", storage.ListOptions{ResourceVersion: deletedPodRV, Predicate: storage.Everything}, result); err != nil {
|
options = storage.ListOptions{
|
||||||
|
ResourceVersion: deletedPodRV,
|
||||||
|
Predicate: storage.Everything,
|
||||||
|
}
|
||||||
|
if err := cacher.List(context.TODO(), "pods/ns", options, result); err != nil {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if result.ListMeta.ResourceVersion != deletedPodRV {
|
if result.ListMeta.ResourceVersion != deletedPodRV {
|
||||||
@ -361,7 +368,11 @@ func TestTooLargeResourceVersionList(t *testing.T) {
|
|||||||
listRV := strconv.Itoa(int(rv + 10))
|
listRV := strconv.Itoa(int(rv + 10))
|
||||||
|
|
||||||
result := &example.PodList{}
|
result := &example.PodList{}
|
||||||
err = cacher.List(context.TODO(), "pods/ns", storage.ListOptions{ResourceVersion: listRV, Predicate: storage.Everything}, result)
|
options := storage.ListOptions{
|
||||||
|
ResourceVersion: listRV,
|
||||||
|
Predicate: storage.Everything,
|
||||||
|
}
|
||||||
|
err = cacher.List(context.TODO(), "pods/ns", options, result)
|
||||||
if !errors.IsTimeout(err) {
|
if !errors.IsTimeout(err) {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user