Parallelize cacher list tests

Kubernetes-commit: eca90dab3f553c5794e780c67e17ae75d9acb65b
This commit is contained in:
Jordan Liggitt 2025-03-31 15:17:04 -04:00 committed by Kubernetes Publisher
parent e228aeaf39
commit 1776f0c3f2
2 changed files with 20 additions and 30 deletions

View File

@ -176,50 +176,34 @@ func TestListPaging(t *testing.T) {
storagetesting.RunTestListPaging(ctx, t, cacher)
}
func TestList(t *testing.T) {
func TestLists(t *testing.T) {
for _, consistentRead := range []bool{true, false} {
t.Run(fmt.Sprintf("ConsistentListFromCache=%v", consistentRead), func(t *testing.T) {
for _, listFromCacheSnapshot := range []bool{true, false} {
t.Run(fmt.Sprintf("ListFromCacheSnapsthot=%v", listFromCacheSnapshot), func(t *testing.T) {
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ListFromCacheSnapshot, listFromCacheSnapshot)
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ConsistentListFromCache, consistentRead)
for _, listFromCacheSnapshot := range []bool{true, false} {
t.Run(fmt.Sprintf("ConsistentListFromCache=%v,ListFromCacheSnapshot=%v", consistentRead, listFromCacheSnapshot), func(t *testing.T) {
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ListFromCacheSnapshot, listFromCacheSnapshot)
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ConsistentListFromCache, consistentRead)
t.Run("List", func(t *testing.T) {
t.Parallel()
ctx, cacher, server, terminate := testSetupWithEtcdServer(t)
t.Cleanup(terminate)
storagetesting.RunTestList(ctx, t, cacher, increaseRV(server.V3Client.Client), true)
})
}
})
}
}
func TestConsistentList(t *testing.T) {
for _, consistentRead := range []bool{true, false} {
t.Run(fmt.Sprintf("ConsistentListFromCache=%v", consistentRead), func(t *testing.T) {
for _, listFromCacheSnapshot := range []bool{true, false} {
t.Run(fmt.Sprintf("ListFromCacheSnapsthot=%v", listFromCacheSnapshot), func(t *testing.T) {
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ListFromCacheSnapshot, listFromCacheSnapshot)
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ConsistentListFromCache, consistentRead)
t.Run("ConsistentList", func(t *testing.T) {
t.Parallel()
ctx, cacher, server, terminate := testSetupWithEtcdServer(t)
t.Cleanup(terminate)
storagetesting.RunTestConsistentList(ctx, t, cacher, increaseRV(server.V3Client.Client), true, consistentRead, listFromCacheSnapshot)
})
}
})
}
}
func TestGetListNonRecursive(t *testing.T) {
for _, consistentRead := range []bool{true, false} {
t.Run(fmt.Sprintf("ConsistentListFromCache=%v", consistentRead), func(t *testing.T) {
for _, listFromCacheSnapshot := range []bool{true, false} {
t.Run(fmt.Sprintf("ListFromCacheSnapsthot=%v", listFromCacheSnapshot), func(t *testing.T) {
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ListFromCacheSnapshot, listFromCacheSnapshot)
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ConsistentListFromCache, consistentRead)
t.Run("GetListNonRecursive", func(t *testing.T) {
t.Parallel()
ctx, cacher, server, terminate := testSetupWithEtcdServer(t)
t.Cleanup(terminate)
storagetesting.RunTestGetListNonRecursive(ctx, t, increaseRV(server.V3Client.Client), cacher)
})
}
})
})
}
}
}

View File

@ -22,6 +22,7 @@ import (
"net/url"
"os"
"strconv"
"sync"
"testing"
"time"
@ -79,6 +80,8 @@ func NewTestConfig(t testing.TB) *embed.Config {
return cfg
}
var autoPortLock sync.Mutex
// RunEtcd starts an embedded etcd server with the provided config
// (or NewTestConfig(t) if nil), and returns a client connected to the server.
// The server is terminated when the test ends.
@ -86,6 +89,9 @@ func RunEtcd(t testing.TB, cfg *embed.Config) *kubernetes.Client {
t.Helper()
if cfg == nil {
// if we have to autopick free ports, lock until we successfully start the server on the ports we chose
autoPortLock.Lock()
defer autoPortLock.Unlock()
cfg = NewTestConfig(t)
}