Parallelize cacher list tests

This commit is contained in:
Jordan Liggitt 2025-03-31 15:17:04 -04:00 committed by Benjamin Wang
parent 1a15d582ae
commit eca90dab3f
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) storagetesting.RunTestListPaging(ctx, t, cacher)
} }
func TestList(t *testing.T) { func TestLists(t *testing.T) {
for _, consistentRead := range []bool{true, false} { for _, consistentRead := range []bool{true, false} {
t.Run(fmt.Sprintf("ConsistentListFromCache=%v", consistentRead), func(t *testing.T) { for _, listFromCacheSnapshot := range []bool{true, false} {
for _, listFromCacheSnapshot := range []bool{true, false} { t.Run(fmt.Sprintf("ConsistentListFromCache=%v,ListFromCacheSnapshot=%v", consistentRead, listFromCacheSnapshot), func(t *testing.T) {
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.ListFromCacheSnapshot, listFromCacheSnapshot) featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ConsistentListFromCache, consistentRead)
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ConsistentListFromCache, consistentRead) t.Run("List", func(t *testing.T) {
t.Parallel()
ctx, cacher, server, terminate := testSetupWithEtcdServer(t) ctx, cacher, server, terminate := testSetupWithEtcdServer(t)
t.Cleanup(terminate) t.Cleanup(terminate)
storagetesting.RunTestList(ctx, t, cacher, increaseRV(server.V3Client.Client), true) storagetesting.RunTestList(ctx, t, cacher, increaseRV(server.V3Client.Client), true)
}) })
}
}) t.Run("ConsistentList", func(t *testing.T) {
} t.Parallel()
}
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)
ctx, cacher, server, terminate := testSetupWithEtcdServer(t) ctx, cacher, server, terminate := testSetupWithEtcdServer(t)
t.Cleanup(terminate) t.Cleanup(terminate)
storagetesting.RunTestConsistentList(ctx, t, cacher, increaseRV(server.V3Client.Client), true, consistentRead, listFromCacheSnapshot) storagetesting.RunTestConsistentList(ctx, t, cacher, increaseRV(server.V3Client.Client), true, consistentRead, listFromCacheSnapshot)
}) })
}
})
}
}
func TestGetListNonRecursive(t *testing.T) { t.Run("GetListNonRecursive", func(t *testing.T) {
for _, consistentRead := range []bool{true, false} { t.Parallel()
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)
ctx, cacher, server, terminate := testSetupWithEtcdServer(t) ctx, cacher, server, terminate := testSetupWithEtcdServer(t)
t.Cleanup(terminate) t.Cleanup(terminate)
storagetesting.RunTestGetListNonRecursive(ctx, t, increaseRV(server.V3Client.Client), cacher) storagetesting.RunTestGetListNonRecursive(ctx, t, increaseRV(server.V3Client.Client), cacher)
}) })
} })
}) }
} }
} }

View File

@ -22,6 +22,7 @@ import (
"net/url" "net/url"
"os" "os"
"strconv" "strconv"
"sync"
"testing" "testing"
"time" "time"
@ -79,6 +80,8 @@ func NewTestConfig(t testing.TB) *embed.Config {
return cfg return cfg
} }
var autoPortLock sync.Mutex
// RunEtcd starts an embedded etcd server with the provided config // RunEtcd starts an embedded etcd server with the provided config
// (or NewTestConfig(t) if nil), and returns a client connected to the server. // (or NewTestConfig(t) if nil), and returns a client connected to the server.
// The server is terminated when the test ends. // The server is terminated when the test ends.
@ -86,6 +89,9 @@ func RunEtcd(t testing.TB, cfg *embed.Config) *kubernetes.Client {
t.Helper() t.Helper()
if cfg == nil { 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) cfg = NewTestConfig(t)
} }