Skip to content

Commit 7dd4a96

Browse files
authored
Make TransportServer tests run in parallel (#3892)
Make tests run in parallel Update TS tests to run in parallel, split negative and positive test scenarios into separate table tests
1 parent ab67547 commit 7dd4a96

File tree

1 file changed

+74
-29
lines changed

1 file changed

+74
-29
lines changed

pkg/apis/configuration/validation/transportserver_test.go

Lines changed: 74 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ func createTransportServerValidator() *TransportServerValidator {
1414

1515
func TestValidateTransportServer(t *testing.T) {
1616
t.Parallel()
17+
1718
ts := v1alpha1.TransportServer{
1819
Spec: v1alpha1.TransportServerSpec{
1920
Listener: v1alpha1.TransportServerListener{
@@ -41,7 +42,7 @@ func TestValidateTransportServer(t *testing.T) {
4142
}
4243
}
4344

44-
func TestValidateTransportServerFails(t *testing.T) {
45+
func TestValidateTransportServer_FailsOnInvalidInput(t *testing.T) {
4546
t.Parallel()
4647
ts := v1alpha1.TransportServer{
4748
Spec: v1alpha1.TransportServerSpec{
@@ -69,6 +70,7 @@ func TestValidateTransportServerFails(t *testing.T) {
6970
}
7071

7172
func TestValidateTransportServerUpstreams(t *testing.T) {
73+
t.Parallel()
7274
tests := []struct {
7375
upstreams []v1alpha1.Upstream
7476
expectedUpstreamNames sets.Set[string]
@@ -103,15 +105,16 @@ func TestValidateTransportServerUpstreams(t *testing.T) {
103105
for _, test := range tests {
104106
allErrs, resultUpstreamNames := validateTransportServerUpstreams(test.upstreams, field.NewPath("upstreams"), true)
105107
if len(allErrs) > 0 {
106-
t.Errorf("validateTransportServerUpstreams() returned errors %v for valid input for the case of %s", allErrs, test.msg)
108+
t.Fatalf("validateTransportServerUpstreams() returned errors %v for valid input for the case of %s", allErrs, test.msg)
107109
}
108110
if !resultUpstreamNames.Equal(test.expectedUpstreamNames) {
109111
t.Errorf("validateTransportServerUpstreams() returned %v expected %v for the case of %s", resultUpstreamNames, test.expectedUpstreamNames, test.msg)
110112
}
111113
}
112114
}
113115

114-
func TestValidateTransportServerUpstreamsFails(t *testing.T) {
116+
func TestValidateTransportServerUpstreams_FailsOnInvalidInput(t *testing.T) {
117+
t.Parallel()
115118
tests := []struct {
116119
upstreams []v1alpha1.Upstream
117120
expectedUpstreamNames sets.Set[string]
@@ -177,7 +180,7 @@ func TestValidateTransportServerUpstreamsFails(t *testing.T) {
177180
for _, test := range tests {
178181
allErrs, resultUpstreamNames := validateTransportServerUpstreams(test.upstreams, field.NewPath("upstreams"), true)
179182
if len(allErrs) == 0 {
180-
t.Errorf("validateTransportServerUpstreams() returned no errors for the case of %s", test.msg)
183+
t.Fatalf("validateTransportServerUpstreams() returned no errors for the case of %s", test.msg)
181184
}
182185
if !resultUpstreamNames.Equal(test.expectedUpstreamNames) {
183186
t.Errorf("validateTransportServerUpstreams() returned %v expected %v for the case of %s", resultUpstreamNames, test.expectedUpstreamNames, test.msg)
@@ -186,6 +189,7 @@ func TestValidateTransportServerUpstreamsFails(t *testing.T) {
186189
}
187190

188191
func TestValidateTransportServerHost(t *testing.T) {
192+
t.Parallel()
189193
tests := []struct {
190194
host string
191195
isTLSPassthroughListener bool
@@ -209,6 +213,8 @@ func TestValidateTransportServerHost(t *testing.T) {
209213
}
210214

211215
func TestValidateTransportServerLoadBalancingMethod(t *testing.T) {
216+
t.Parallel()
217+
212218
tests := []struct {
213219
method string
214220
isPlus bool
@@ -314,7 +320,7 @@ func TestValidateTransportServerLoadBalancingMethod(t *testing.T) {
314320
for _, test := range tests {
315321
allErrs := validateLoadBalancingMethod(test.method, field.NewPath("method"), test.isPlus)
316322
if !test.hasError && len(allErrs) > 0 {
317-
t.Errorf("validateLoadBalancingMethod(%q, %v) returned errors %v for valid input", test.method, test.isPlus, allErrs)
323+
t.Fatalf("validateLoadBalancingMethod(%q, %v) returned errors %v for valid input", test.method, test.isPlus, allErrs)
318324
}
319325
if test.hasError && len(allErrs) < 1 {
320326
t.Errorf("validateLoadBalancingMethod(%q, %v) failed to return an error for invalid input", test.method, test.isPlus)
@@ -323,6 +329,7 @@ func TestValidateTransportServerLoadBalancingMethod(t *testing.T) {
323329
}
324330

325331
func TestValidateTransportServerSnippet(t *testing.T) {
332+
t.Parallel()
326333
tests := []struct {
327334
snippet string
328335
isSnippetsEnabled bool
@@ -359,7 +366,8 @@ func TestValidateTransportServerSnippet(t *testing.T) {
359366
}
360367
}
361368

362-
func TestValidateTransportServerHostFails(t *testing.T) {
369+
func TestValidateTransportServerHost_FailsOnInvalidInput(t *testing.T) {
370+
t.Parallel()
363371
tests := []struct {
364372
host string
365373
isTLSPassthroughListener bool
@@ -383,6 +391,7 @@ func TestValidateTransportServerHostFails(t *testing.T) {
383391
}
384392

385393
func TestValidateTransportListener(t *testing.T) {
394+
t.Parallel()
386395
tests := []struct {
387396
listener *v1alpha1.TransportServerListener
388397
tlsPassthrough bool
@@ -422,7 +431,8 @@ func TestValidateTransportListener(t *testing.T) {
422431
}
423432
}
424433

425-
func TestValidateTransportListenerFails(t *testing.T) {
434+
func TestValidateTransportListener_FailsOnInvalidInput(t *testing.T) {
435+
t.Parallel()
426436
tests := []struct {
427437
listener *v1alpha1.TransportServerListener
428438
tlsPassthrough bool
@@ -477,6 +487,7 @@ func TestValidateTransportListenerFails(t *testing.T) {
477487
}
478488

479489
func TestValidateIsPotentialTLSPassthroughListener(t *testing.T) {
490+
t.Parallel()
480491
tests := []struct {
481492
listener *v1alpha1.TransportServerListener
482493
expected bool
@@ -513,6 +524,7 @@ func TestValidateIsPotentialTLSPassthroughListener(t *testing.T) {
513524
}
514525

515526
func TestValidateListenerProtocol(t *testing.T) {
527+
t.Parallel()
516528
validProtocols := []string{
517529
"TCP",
518530
"UDP",
@@ -524,7 +536,10 @@ func TestValidateListenerProtocol(t *testing.T) {
524536
t.Errorf("validateListenerProtocol(%q) returned errors %v for valid input", p, allErrs)
525537
}
526538
}
539+
}
527540

541+
func TestValidateListenerProtocol_FailsOnInvalidInput(t *testing.T) {
542+
t.Parallel()
528543
invalidProtocols := []string{
529544
"",
530545
"HTTP",
@@ -541,6 +556,7 @@ func TestValidateListenerProtocol(t *testing.T) {
541556
}
542557

543558
func TestValidateTSUpstreamHealthChecks(t *testing.T) {
559+
t.Parallel()
544560
tests := []struct {
545561
healthCheck *v1alpha1.HealthCheck
546562
msg string
@@ -574,7 +590,8 @@ func TestValidateTSUpstreamHealthChecks(t *testing.T) {
574590
}
575591
}
576592

577-
func TestValidateTSUpstreamHealthChecksFails(t *testing.T) {
593+
func TestValidateTSUpstreamHealthChecks_FailsOnInvalidInput(t *testing.T) {
594+
t.Parallel()
578595
tests := []struct {
579596
healthCheck *v1alpha1.HealthCheck
580597
msg string
@@ -662,6 +679,7 @@ func TestValidateTSUpstreamHealthChecksFails(t *testing.T) {
662679
}
663680

664681
func TestValidateUpstreamParameters(t *testing.T) {
682+
t.Parallel()
665683
tests := []struct {
666684
parameters *v1alpha1.UpstreamParameters
667685
msg string
@@ -685,6 +703,7 @@ func TestValidateUpstreamParameters(t *testing.T) {
685703
}
686704

687705
func TestValidateSessionParameters(t *testing.T) {
706+
t.Parallel()
688707
tests := []struct {
689708
parameters *v1alpha1.SessionParameters
690709
msg string
@@ -713,7 +732,8 @@ func TestValidateSessionParameters(t *testing.T) {
713732
}
714733
}
715734

716-
func TestValidateSessionParametersFails(t *testing.T) {
735+
func TestValidateSessionParameters_FailsOnInvalidInput(t *testing.T) {
736+
t.Parallel()
717737
tests := []struct {
718738
parameters *v1alpha1.SessionParameters
719739
msg string
@@ -735,6 +755,7 @@ func TestValidateSessionParametersFails(t *testing.T) {
735755
}
736756

737757
func TestValidateUDPUpstreamParameter(t *testing.T) {
758+
t.Parallel()
738759
validInput := []struct {
739760
parameter *int
740761
protocol string
@@ -765,7 +786,8 @@ func TestValidateUDPUpstreamParameter(t *testing.T) {
765786
}
766787
}
767788

768-
func TestValidateUDPUpstreamParameterFails(t *testing.T) {
789+
func TestValidateUDPUpstreamParameter_FailsOnInvalidInput(t *testing.T) {
790+
t.Parallel()
769791
invalidInput := []struct {
770792
parameter *int
771793
protocol string
@@ -789,6 +811,7 @@ func TestValidateUDPUpstreamParameterFails(t *testing.T) {
789811
}
790812

791813
func TestValidateTransportServerAction(t *testing.T) {
814+
t.Parallel()
792815
upstreamNames := map[string]sets.Empty{
793816
"test": {},
794817
}
@@ -803,7 +826,8 @@ func TestValidateTransportServerAction(t *testing.T) {
803826
}
804827
}
805828

806-
func TestValidateTransportServerActionFails(t *testing.T) {
829+
func TestValidateTransportServerAction_FailsOnInvalidInput(t *testing.T) {
830+
t.Parallel()
807831
upstreamNames := map[string]sets.Empty{}
808832

809833
tests := []struct {
@@ -833,23 +857,29 @@ func TestValidateTransportServerActionFails(t *testing.T) {
833857
}
834858

835859
func TestValidateMatchSend(t *testing.T) {
860+
t.Parallel()
836861
validInput := []string{
837862
"",
838863
"abc",
839864
"hello${world}",
840865
`hello\x00`,
841866
}
842-
invalidInput := []string{
843-
`hello"world`,
844-
`\x1x`,
845-
}
846867

847868
for _, send := range validInput {
848869
allErrs := validateMatchSend(send, field.NewPath("send"))
849870
if len(allErrs) > 0 {
850871
t.Errorf("validateMatchSend(%q) returned errors %v for valid input", send, allErrs)
851872
}
852873
}
874+
}
875+
876+
func TestValidateMatchSend_FailsOnInvalidInput(t *testing.T) {
877+
t.Parallel()
878+
invalidInput := []string{
879+
`hello"world`,
880+
`\x1x`,
881+
}
882+
853883
for _, send := range invalidInput {
854884
allErrs := validateMatchSend(send, field.NewPath("send"))
855885
if len(allErrs) == 0 {
@@ -859,6 +889,7 @@ func TestValidateMatchSend(t *testing.T) {
859889
}
860890

861891
func TestValidateHexString(t *testing.T) {
892+
t.Parallel()
862893
validInput := []string{
863894
"",
864895
"abc",
@@ -868,6 +899,17 @@ func TestValidateHexString(t *testing.T) {
868899
`\xff`,
869900
`\xaaFFabc\x12`,
870901
}
902+
903+
for _, s := range validInput {
904+
err := validateHexString(s)
905+
if err != nil {
906+
t.Errorf("validateHexString(%q) returned error %v for valid input", s, err)
907+
}
908+
}
909+
}
910+
911+
func TestValidateHexString_FailsOnInvalidInput(t *testing.T) {
912+
t.Parallel()
871913
invalidInput := []string{
872914
`\x`,
873915
`\x1`,
@@ -876,12 +918,6 @@ func TestValidateHexString(t *testing.T) {
876918
`\xaaFFabc\xx12`, // \xx1 is invalid
877919
}
878920

879-
for _, s := range validInput {
880-
err := validateHexString(s)
881-
if err != nil {
882-
t.Errorf("validateHexString(%q) returned error %v for valid input", s, err)
883-
}
884-
}
885921
for _, s := range invalidInput {
886922
err := validateHexString(s)
887923
if err == nil {
@@ -891,6 +927,7 @@ func TestValidateHexString(t *testing.T) {
891927
}
892928

893929
func TestValidateMatchExpect(t *testing.T) {
930+
t.Parallel()
894931
validInput := []string{
895932
``,
896933
`abc`,
@@ -900,6 +937,17 @@ func TestValidateMatchExpect(t *testing.T) {
900937
`~`,
901938
`~*`,
902939
}
940+
941+
for _, input := range validInput {
942+
allErrs := validateMatchExpect(input, field.NewPath("expect"))
943+
if len(allErrs) > 0 {
944+
t.Errorf("validateMatchExpect(%q) returned errors %v for valid input", input, allErrs)
945+
}
946+
}
947+
}
948+
949+
func TestValidateMatchExpect_FailsOnInvalidInput(t *testing.T) {
950+
t.Parallel()
903951
invalidInput := []string{
904952
`hello"world`,
905953
`~hello"world`,
@@ -911,12 +959,6 @@ func TestValidateMatchExpect(t *testing.T) {
911959
`~{1}`,
912960
}
913961

914-
for _, input := range validInput {
915-
allErrs := validateMatchExpect(input, field.NewPath("expect"))
916-
if len(allErrs) > 0 {
917-
t.Errorf("validateMatchExpect(%q) returned errors %v for valid input", input, allErrs)
918-
}
919-
}
920962
for _, input := range invalidInput {
921963
allErrs := validateMatchExpect(input, field.NewPath("expect"))
922964
if len(allErrs) == 0 {
@@ -940,8 +982,11 @@ func TestValidateTsTLS(t *testing.T) {
940982
t.Errorf("validateTLS() returned errors %v for valid input %v", allErrs, tls)
941983
}
942984
}
985+
}
943986

944-
tests := []struct {
987+
func TestValidateTsTLS_FailsOnInvalidInput(t *testing.T) {
988+
t.Parallel()
989+
invalidTLSes := []struct {
945990
tls *v1alpha1.TLS
946991
isTLSPassthrough bool
947992
}{
@@ -971,7 +1016,7 @@ func TestValidateTsTLS(t *testing.T) {
9711016
},
9721017
}
9731018

974-
for _, test := range tests {
1019+
for _, test := range invalidTLSes {
9751020
allErrs := validateTLS(test.tls, test.isTLSPassthrough, field.NewPath("tls"))
9761021
if len(allErrs) == 0 {
9771022
t.Errorf("validateTLS() returned no errors for invalid input %v", test)

0 commit comments

Comments
 (0)