Skip to content

Commit eca90da

Browse files
liggittahrtr
authored andcommitted
Parallelize cacher list tests
1 parent 1a15d58 commit eca90da

File tree

2 files changed

+20
-30
lines changed

2 files changed

+20
-30
lines changed

staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_test.go

+14-30
Original file line numberDiff line numberDiff line change
@@ -176,50 +176,34 @@ func TestListPaging(t *testing.T) {
176176
storagetesting.RunTestListPaging(ctx, t, cacher)
177177
}
178178

179-
func TestList(t *testing.T) {
179+
func TestLists(t *testing.T) {
180180
for _, consistentRead := range []bool{true, false} {
181-
t.Run(fmt.Sprintf("ConsistentListFromCache=%v", consistentRead), func(t *testing.T) {
182-
for _, listFromCacheSnapshot := range []bool{true, false} {
183-
t.Run(fmt.Sprintf("ListFromCacheSnapsthot=%v", listFromCacheSnapshot), func(t *testing.T) {
184-
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ListFromCacheSnapshot, listFromCacheSnapshot)
185-
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ConsistentListFromCache, consistentRead)
181+
for _, listFromCacheSnapshot := range []bool{true, false} {
182+
t.Run(fmt.Sprintf("ConsistentListFromCache=%v,ListFromCacheSnapshot=%v", consistentRead, listFromCacheSnapshot), func(t *testing.T) {
183+
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ListFromCacheSnapshot, listFromCacheSnapshot)
184+
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ConsistentListFromCache, consistentRead)
185+
t.Run("List", func(t *testing.T) {
186+
t.Parallel()
186187
ctx, cacher, server, terminate := testSetupWithEtcdServer(t)
187188
t.Cleanup(terminate)
188189
storagetesting.RunTestList(ctx, t, cacher, increaseRV(server.V3Client.Client), true)
189190
})
190-
}
191-
})
192-
}
193-
}
194-
func TestConsistentList(t *testing.T) {
195-
for _, consistentRead := range []bool{true, false} {
196-
t.Run(fmt.Sprintf("ConsistentListFromCache=%v", consistentRead), func(t *testing.T) {
197-
for _, listFromCacheSnapshot := range []bool{true, false} {
198-
t.Run(fmt.Sprintf("ListFromCacheSnapsthot=%v", listFromCacheSnapshot), func(t *testing.T) {
199-
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ListFromCacheSnapshot, listFromCacheSnapshot)
200-
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ConsistentListFromCache, consistentRead)
191+
192+
t.Run("ConsistentList", func(t *testing.T) {
193+
t.Parallel()
201194
ctx, cacher, server, terminate := testSetupWithEtcdServer(t)
202195
t.Cleanup(terminate)
203196
storagetesting.RunTestConsistentList(ctx, t, cacher, increaseRV(server.V3Client.Client), true, consistentRead, listFromCacheSnapshot)
204197
})
205-
}
206-
})
207-
}
208-
}
209198

210-
func TestGetListNonRecursive(t *testing.T) {
211-
for _, consistentRead := range []bool{true, false} {
212-
t.Run(fmt.Sprintf("ConsistentListFromCache=%v", consistentRead), func(t *testing.T) {
213-
for _, listFromCacheSnapshot := range []bool{true, false} {
214-
t.Run(fmt.Sprintf("ListFromCacheSnapsthot=%v", listFromCacheSnapshot), func(t *testing.T) {
215-
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ListFromCacheSnapshot, listFromCacheSnapshot)
216-
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ConsistentListFromCache, consistentRead)
199+
t.Run("GetListNonRecursive", func(t *testing.T) {
200+
t.Parallel()
217201
ctx, cacher, server, terminate := testSetupWithEtcdServer(t)
218202
t.Cleanup(terminate)
219203
storagetesting.RunTestGetListNonRecursive(ctx, t, increaseRV(server.V3Client.Client), cacher)
220204
})
221-
}
222-
})
205+
})
206+
}
223207
}
224208
}
225209

staging/src/k8s.io/apiserver/pkg/storage/etcd3/testserver/test_server.go

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"net/url"
2323
"os"
2424
"strconv"
25+
"sync"
2526
"testing"
2627
"time"
2728

@@ -79,13 +80,18 @@ func NewTestConfig(t testing.TB) *embed.Config {
7980
return cfg
8081
}
8182

83+
var autoPortLock sync.Mutex
84+
8285
// RunEtcd starts an embedded etcd server with the provided config
8386
// (or NewTestConfig(t) if nil), and returns a client connected to the server.
8487
// The server is terminated when the test ends.
8588
func RunEtcd(t testing.TB, cfg *embed.Config) *kubernetes.Client {
8689
t.Helper()
8790

8891
if cfg == nil {
92+
// if we have to autopick free ports, lock until we successfully start the server on the ports we chose
93+
autoPortLock.Lock()
94+
defer autoPortLock.Unlock()
8995
cfg = NewTestConfig(t)
9096
}
9197

0 commit comments

Comments
 (0)