Parallelize tests cases in some storage tests

This commit is contained in:
Wojciech Tyczyński 2022-11-04 10:23:40 +01:00
parent e301306d89
commit 6d85f947bf
2 changed files with 19 additions and 13 deletions

View File

@ -184,7 +184,10 @@ func RunTestGet(ctx context.Context, t *testing.T, store storage.Interface) {
}} }}
for _, tt := range tests { for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
t.Parallel()
out := &example.Pod{} out := &example.Pod{}
err := store.Get(ctx, tt.key, storage.GetOptions{IgnoreNotFound: tt.ignoreNotFound, ResourceVersion: tt.rv}, out) err := store.Get(ctx, tt.key, storage.GetOptions{IgnoreNotFound: tt.ignoreNotFound, ResourceVersion: tt.rv}, out)
if tt.expectNotFoundErr { if tt.expectNotFoundErr {
@ -1091,12 +1094,11 @@ func RunTestGetListNonRecursive(ctx context.Context, t *testing.T, store storage
rv: "0", rv: "0",
rvMatch: metav1.ResourceVersionMatchNotOlderThan, rvMatch: metav1.ResourceVersionMatchNotOlderThan,
}, { }, {
name: "existing key, resourceVersion=previous, resourceVersionMatch=notOlderThan", name: "existing key, resourceVersion=current",
key: key, key: key,
pred: storage.Everything, pred: storage.Everything,
expectedAlternatives: [][]example.Pod{{*prevStoredObj}, {*storedObj}}, expectedOut: []example.Pod{*storedObj},
rv: fmt.Sprintf("%d", prevRV), rv: fmt.Sprintf("%d", currentRV),
rvMatch: metav1.ResourceVersionMatchNotOlderThan,
}, { }, {
name: "existing key, resourceVersion=current, resourceVersionMatch=notOlderThan", name: "existing key, resourceVersion=current, resourceVersionMatch=notOlderThan",
key: key, key: key,
@ -1105,11 +1107,12 @@ func RunTestGetListNonRecursive(ctx context.Context, t *testing.T, store storage
rv: fmt.Sprintf("%d", currentRV), rv: fmt.Sprintf("%d", currentRV),
rvMatch: metav1.ResourceVersionMatchNotOlderThan, rvMatch: metav1.ResourceVersionMatchNotOlderThan,
}, { }, {
name: "existing key, resourceVersion=current", name: "existing key, resourceVersion=previous, resourceVersionMatch=notOlderThan",
key: key, key: key,
pred: storage.Everything, pred: storage.Everything,
expectedOut: []example.Pod{*storedObj}, expectedAlternatives: [][]example.Pod{{*prevStoredObj}, {*storedObj}},
rv: fmt.Sprintf("%d", currentRV), rv: fmt.Sprintf("%d", prevRV),
rvMatch: metav1.ResourceVersionMatchNotOlderThan,
}, { }, {
name: "existing key, resourceVersion=current, resourceVersionMatch=exact", name: "existing key, resourceVersion=current, resourceVersionMatch=exact",
key: key, key: key,
@ -1151,7 +1154,10 @@ func RunTestGetListNonRecursive(ctx context.Context, t *testing.T, store storage
}} }}
for _, tt := range tests { for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
t.Parallel()
out := &example.PodList{} out := &example.PodList{}
storageOpts := storage.ListOptions{ storageOpts := storage.ListOptions{
ResourceVersion: tt.rv, ResourceVersion: tt.rv,

View File

@ -165,13 +165,13 @@ func updatePod(t *testing.T, s storage.Interface, obj, old *example.Pod) *exampl
func TestGet(t *testing.T) { func TestGet(t *testing.T) {
ctx, cacher, terminate := testSetup(t) ctx, cacher, terminate := testSetup(t)
defer terminate() t.Cleanup(terminate)
storagetesting.RunTestGet(ctx, t, cacher) storagetesting.RunTestGet(ctx, t, cacher)
} }
func TestGetListNonRecursive(t *testing.T) { func TestGetListNonRecursive(t *testing.T) {
ctx, cacher, terminate := testSetup(t) ctx, cacher, terminate := testSetup(t)
defer terminate() t.Cleanup(terminate)
storagetesting.RunTestGetListNonRecursive(ctx, t, cacher) storagetesting.RunTestGetListNonRecursive(ctx, t, cacher)
} }