Skip to content

Commit cc82045

Browse files
committed
Run tests in internal/mode/static/state in parallel (1) (nginx#2534)
1 parent 088a6d7 commit cc82045

19 files changed

+164
-20
lines changed

internal/mode/static/state/changed_predicate_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
)
1414

1515
func TestFuncPredicate(t *testing.T) {
16+
t.Parallel()
1617
alwaysTrueFunc := func(_ ngftypes.ObjectType, _ types.NamespacedName) bool { return true }
1718
emptyObject := &v1.Pod{}
1819

@@ -25,6 +26,7 @@ func TestFuncPredicate(t *testing.T) {
2526
}
2627

2728
func TestFuncPredicate_Panic(t *testing.T) {
29+
t.Parallel()
2830
alwaysTrueFunc := func(_ ngftypes.ObjectType, _ types.NamespacedName) bool { return true }
2931

3032
p := funcPredicate{stateChanged: alwaysTrueFunc}
@@ -38,13 +40,15 @@ func TestFuncPredicate_Panic(t *testing.T) {
3840
}
3941

4042
func TestAnnotationChangedPredicate_Delete(t *testing.T) {
43+
t.Parallel()
4144
p := annotationChangedPredicate{}
4245

4346
g := NewWithT(t)
4447
g.Expect(p.delete(nil, types.NamespacedName{})).To(BeTrue())
4548
}
4649

4750
func TestAnnotationChangedPredicate_Update(t *testing.T) {
51+
t.Parallel()
4852
annotation := "test"
4953

5054
tests := []struct {
@@ -140,6 +144,7 @@ func TestAnnotationChangedPredicate_Update(t *testing.T) {
140144

141145
for _, test := range tests {
142146
t.Run(test.name, func(t *testing.T) {
147+
t.Parallel()
143148
g := NewWithT(t)
144149
if test.expPanic {
145150
upsert := func() {

internal/mode/static/state/dataplane/configuration_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func createFakePolicy(name string, kind string) policies.Policy {
109109
}
110110

111111
func TestBuildConfiguration(t *testing.T) {
112+
t.Parallel()
112113
const (
113114
invalidMatchesPath = "/not-valid-matches"
114115
invalidFiltersPath = "/not-valid-filters"
@@ -2231,6 +2232,7 @@ func TestBuildConfiguration(t *testing.T) {
22312232

22322233
for _, test := range tests {
22332234
t.Run(test.msg, func(t *testing.T) {
2235+
t.Parallel()
22342236
g := NewWithT(t)
22352237

22362238
result := BuildConfiguration(
@@ -2255,6 +2257,7 @@ func TestBuildConfiguration(t *testing.T) {
22552257
}
22562258

22572259
func TestGetPath(t *testing.T) {
2260+
t.Parallel()
22582261
tests := []struct {
22592262
path *v1.HTTPPathMatch
22602263
expected string
@@ -2284,6 +2287,7 @@ func TestGetPath(t *testing.T) {
22842287

22852288
for _, test := range tests {
22862289
t.Run(test.msg, func(t *testing.T) {
2290+
t.Parallel()
22872291
g := NewWithT(t)
22882292
result := getPath(test.path)
22892293
g.Expect(result).To(Equal(test.expected))
@@ -2292,6 +2296,7 @@ func TestGetPath(t *testing.T) {
22922296
}
22932297

22942298
func TestCreateFilters(t *testing.T) {
2299+
t.Parallel()
22952300
redirect1 := v1.HTTPRouteFilter{
22962301
Type: v1.HTTPRouteFilterRequestRedirect,
22972302
RequestRedirect: &v1.HTTPRequestRedirectFilter{
@@ -2451,6 +2456,7 @@ func TestCreateFilters(t *testing.T) {
24512456

24522457
for _, test := range tests {
24532458
t.Run(test.msg, func(t *testing.T) {
2459+
t.Parallel()
24542460
g := NewWithT(t)
24552461
result := createHTTPFilters(test.filters)
24562462

@@ -2460,6 +2466,7 @@ func TestCreateFilters(t *testing.T) {
24602466
}
24612467

24622468
func TestGetListenerHostname(t *testing.T) {
2469+
t.Parallel()
24632470
var emptyHostname v1.Hostname
24642471
var hostname v1.Hostname = "example.com"
24652472

@@ -2487,6 +2494,7 @@ func TestGetListenerHostname(t *testing.T) {
24872494

24882495
for _, test := range tests {
24892496
t.Run(test.msg, func(t *testing.T) {
2497+
t.Parallel()
24902498
g := NewWithT(t)
24912499
result := getListenerHostname(test.hostname)
24922500
g.Expect(result).To(Equal(test.expected))
@@ -2509,6 +2517,7 @@ func refsToValidRules(refs ...[]graph.BackendRef) []graph.RouteRule {
25092517
}
25102518

25112519
func TestBuildUpstreams(t *testing.T) {
2520+
t.Parallel()
25122521
fooEndpoints := []resolver.Endpoint{
25132522
{
25142523
Address: "10.0.0.0",
@@ -2776,6 +2785,7 @@ func TestBuildUpstreams(t *testing.T) {
27762785
}
27772786

27782787
func TestBuildBackendGroups(t *testing.T) {
2788+
t.Parallel()
27792789
createBackendGroup := func(name string, ruleIdx int, backendNames ...string) BackendGroup {
27802790
backends := make([]Backend, len(backendNames))
27812791
for i, name := range backendNames {
@@ -2848,6 +2858,7 @@ func TestBuildBackendGroups(t *testing.T) {
28482858
}
28492859

28502860
func TestHostnameMoreSpecific(t *testing.T) {
2861+
t.Parallel()
28512862
tests := []struct {
28522863
host1 *v1.Hostname
28532864
host2 *v1.Hostname
@@ -2900,6 +2911,7 @@ func TestHostnameMoreSpecific(t *testing.T) {
29002911

29012912
for _, tc := range tests {
29022913
t.Run(tc.msg, func(t *testing.T) {
2914+
t.Parallel()
29032915
g := NewWithT(t)
29042916

29052917
g.Expect(listenerHostnameMoreSpecific(tc.host1, tc.host2)).To(Equal(tc.host1Wins))
@@ -2908,6 +2920,7 @@ func TestHostnameMoreSpecific(t *testing.T) {
29082920
}
29092921

29102922
func TestConvertBackendTLS(t *testing.T) {
2923+
t.Parallel()
29112924
btpCaCertRefs := &graph.BackendTLSPolicy{
29122925
Source: &v1alpha3.BackendTLSPolicy{
29132926
ObjectMeta: metav1.ObjectMeta{
@@ -2976,6 +2989,7 @@ func TestConvertBackendTLS(t *testing.T) {
29762989

29772990
for _, tc := range tests {
29782991
t.Run(tc.msg, func(t *testing.T) {
2992+
t.Parallel()
29792993
g := NewWithT(t)
29802994

29812995
g.Expect(convertBackendTLS(tc.btp)).To(Equal(tc.expected))
@@ -2984,6 +2998,7 @@ func TestConvertBackendTLS(t *testing.T) {
29842998
}
29852999

29863000
func TestBuildTelemetry(t *testing.T) {
3001+
t.Parallel()
29873002
telemetryConfigured := &graph.NginxProxy{
29883003
Source: &ngfAPI.NginxProxy{
29893004
Spec: ngfAPI.NginxProxySpec{
@@ -3206,6 +3221,7 @@ func TestBuildTelemetry(t *testing.T) {
32063221

32073222
for _, tc := range tests {
32083223
t.Run(tc.msg, func(t *testing.T) {
3224+
t.Parallel()
32093225
g := NewWithT(t)
32103226
tel := buildTelemetry(tc.g)
32113227
sort.Slice(tel.Ratios, func(i, j int) bool {
@@ -3217,6 +3233,7 @@ func TestBuildTelemetry(t *testing.T) {
32173233
}
32183234

32193235
func TestBuildPolicies(t *testing.T) {
3236+
t.Parallel()
32203237
getPolicy := func(kind, name string) policies.Policy {
32213238
return &policiesfakes.FakePolicy{
32223239
GetNameStub: func() string {
@@ -3281,6 +3298,7 @@ func TestBuildPolicies(t *testing.T) {
32813298

32823299
for _, test := range tests {
32833300
t.Run(test.name, func(t *testing.T) {
3301+
t.Parallel()
32843302
g := NewWithT(t)
32853303

32863304
pols := buildPolicies(test.policies)
@@ -3293,6 +3311,7 @@ func TestBuildPolicies(t *testing.T) {
32933311
}
32943312

32953313
func TestGetAllowedAddressType(t *testing.T) {
3314+
t.Parallel()
32963315
test := []struct {
32973316
msg string
32983317
ipFamily IPFamilyType
@@ -3322,18 +3341,21 @@ func TestGetAllowedAddressType(t *testing.T) {
33223341

33233342
for _, tc := range test {
33243343
t.Run(tc.msg, func(t *testing.T) {
3344+
t.Parallel()
33253345
g := NewWithT(t)
33263346
g.Expect(getAllowedAddressType(tc.ipFamily)).To(Equal(tc.expected))
33273347
})
33283348
}
33293349
}
33303350

33313351
func TestCreateRatioVarName(t *testing.T) {
3352+
t.Parallel()
33323353
g := NewWithT(t)
33333354
g.Expect(CreateRatioVarName(25)).To(Equal("$otel_ratio_25"))
33343355
}
33353356

33363357
func TestCreatePassthroughServers(t *testing.T) {
3358+
t.Parallel()
33373359
getL4RouteKey := func(name string) graph.L4RouteKey {
33383360
return graph.L4RouteKey{
33393361
NamespacedName: types.NamespacedName{
@@ -3470,6 +3492,7 @@ func TestCreatePassthroughServers(t *testing.T) {
34703492
}
34713493

34723494
func TestBuildStreamUpstreams(t *testing.T) {
3495+
t.Parallel()
34733496
getL4RouteKey := func(name string) graph.L4RouteKey {
34743497
return graph.L4RouteKey{
34753498
NamespacedName: types.NamespacedName{
@@ -3601,6 +3624,7 @@ func TestBuildStreamUpstreams(t *testing.T) {
36013624
}
36023625

36033626
func TestBuildRewriteIPSettings(t *testing.T) {
3627+
t.Parallel()
36043628
tests := []struct {
36053629
msg string
36063630
g *graph.Graph
@@ -3713,6 +3737,7 @@ func TestBuildRewriteIPSettings(t *testing.T) {
37133737

37143738
for _, tc := range tests {
37153739
t.Run(tc.msg, func(t *testing.T) {
3740+
t.Parallel()
37163741
g := NewWithT(t)
37173742
baseConfig := buildBaseHTTPConfig(tc.g)
37183743
g.Expect(baseConfig.RewriteClientIPSettings).To(Equal(tc.expRewriteIPSettings))

internal/mode/static/state/dataplane/convert_test.go

+19-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
)
1111

1212
func TestConvertMatch(t *testing.T) {
13+
t.Parallel()
1314
path := v1.HTTPPathMatch{
1415
Type: helpers.GetPointer(v1.PathMatchPathPrefix),
1516
Value: helpers.GetPointer("/"),
@@ -115,6 +116,7 @@ func TestConvertMatch(t *testing.T) {
115116

116117
for _, test := range tests {
117118
t.Run(test.name, func(t *testing.T) {
119+
t.Parallel()
118120
g := NewWithT(t)
119121

120122
result := convertMatch(test.match)
@@ -124,6 +126,7 @@ func TestConvertMatch(t *testing.T) {
124126
}
125127

126128
func TestConvertHTTPRequestRedirectFilter(t *testing.T) {
129+
t.Parallel()
127130
tests := []struct {
128131
filter *v1.HTTPRequestRedirectFilter
129132
expected *HTTPRequestRedirectFilter
@@ -153,6 +156,7 @@ func TestConvertHTTPRequestRedirectFilter(t *testing.T) {
153156

154157
for _, test := range tests {
155158
t.Run(test.name, func(t *testing.T) {
159+
t.Parallel()
156160
g := NewWithT(t)
157161

158162
result := convertHTTPRequestRedirectFilter(test.filter)
@@ -162,6 +166,7 @@ func TestConvertHTTPRequestRedirectFilter(t *testing.T) {
162166
}
163167

164168
func TestConvertHTTPURLRewriteFilter(t *testing.T) {
169+
t.Parallel()
165170
tests := []struct {
166171
filter *v1.HTTPURLRewriteFilter
167172
expected *HTTPURLRewriteFilter
@@ -210,6 +215,7 @@ func TestConvertHTTPURLRewriteFilter(t *testing.T) {
210215

211216
for _, test := range tests {
212217
t.Run(test.name, func(t *testing.T) {
218+
t.Parallel()
213219
g := NewWithT(t)
214220

215221
result := convertHTTPURLRewriteFilter(test.filter)
@@ -219,6 +225,7 @@ func TestConvertHTTPURLRewriteFilter(t *testing.T) {
219225
}
220226

221227
func TestConvertHTTPHeaderFilter(t *testing.T) {
228+
t.Parallel()
222229
tests := []struct {
223230
filter *v1.HTTPHeaderFilter
224231
expected *HTTPHeaderFilter
@@ -258,6 +265,7 @@ func TestConvertHTTPHeaderFilter(t *testing.T) {
258265

259266
for _, test := range tests {
260267
t.Run(test.name, func(t *testing.T) {
268+
t.Parallel()
261269
g := NewWithT(t)
262270

263271
result := convertHTTPHeaderFilter(test.filter)
@@ -267,7 +275,7 @@ func TestConvertHTTPHeaderFilter(t *testing.T) {
267275
}
268276

269277
func TestConvertPathType(t *testing.T) {
270-
g := NewWithT(t)
278+
t.Parallel()
271279

272280
tests := []struct {
273281
pathType v1.PathMatchType
@@ -289,11 +297,15 @@ func TestConvertPathType(t *testing.T) {
289297
}
290298

291299
for _, tc := range tests {
292-
if tc.panic {
293-
g.Expect(func() { convertPathType(tc.pathType) }).To(Panic())
294-
} else {
295-
result := convertPathType(tc.pathType)
296-
g.Expect(result).To(Equal(tc.expected))
297-
}
300+
t.Run(string(tc.pathType), func(t *testing.T) {
301+
t.Parallel()
302+
g := NewWithT(t)
303+
if tc.panic {
304+
g.Expect(func() { convertPathType(tc.pathType) }).To(Panic())
305+
} else {
306+
result := convertPathType(tc.pathType)
307+
g.Expect(result).To(Equal(tc.expected))
308+
}
309+
})
298310
}
299311
}

internal/mode/static/state/dataplane/sort_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
)
1313

1414
func TestSort(t *testing.T) {
15+
t.Parallel()
1516
// timestamps
1617
earlier := metav1.Now()
1718
later := metav1.NewTime(earlier.Add(1 * time.Second))

0 commit comments

Comments
 (0)