Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable more parallel tests #2572

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/mode/static/config_updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
)

func TestUpdateControlPlane(t *testing.T) {
t.Parallel()
debugLogCfg := &ngfAPI.NginxGateway{
Spec: ngfAPI.NginxGatewaySpec{
Logging: &ngfAPI.Logging{
Expand Down Expand Up @@ -72,6 +73,7 @@ func TestUpdateControlPlane(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

fakeLogSetter := &staticfakes.FakeLogLevelSetter{
Expand Down Expand Up @@ -118,6 +120,7 @@ func TestValidateLogLevel(t *testing.T) {

for _, level := range validLevels {
t.Run(fmt.Sprintf("valid level %q", level), func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

g.Expect(validateLogLevel(level)).To(Succeed())
Expand Down
19 changes: 19 additions & 0 deletions internal/mode/static/state/graph/backend_refs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func getModifiedRef(mod func(ref gatewayv1.BackendRef) gatewayv1.BackendRef) gat
}

func TestValidateRouteBackendRef(t *testing.T) {
t.Parallel()
tests := []struct {
expectedCondition conditions.Condition
name string
Expand Down Expand Up @@ -85,6 +86,7 @@ func TestValidateRouteBackendRef(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)
alwaysTrueRefGrantResolver := func(_ toResource) bool { return true }

Expand All @@ -97,6 +99,7 @@ func TestValidateRouteBackendRef(t *testing.T) {
}

func TestValidateBackendRef(t *testing.T) {
t.Parallel()
alwaysFalseRefGrantResolver := func(_ toResource) bool { return false }
alwaysTrueRefGrantResolver := func(_ toResource) bool { return true }

Expand Down Expand Up @@ -204,6 +207,7 @@ func TestValidateBackendRef(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

valid, cond := validateBackendRef(test.ref, "test", test.refGrantResolver, field.NewPath("test"))
Expand All @@ -215,6 +219,7 @@ func TestValidateBackendRef(t *testing.T) {
}

func TestValidateWeight(t *testing.T) {
t.Parallel()
validWeights := []int32{0, 1, 1000000}
invalidWeights := []int32{-1, 1000001}

Expand All @@ -231,6 +236,7 @@ func TestValidateWeight(t *testing.T) {
}

func TestGetIPFamilyAndPortFromRef(t *testing.T) {
t.Parallel()
svc1 := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "service1",
Expand Down Expand Up @@ -301,6 +307,7 @@ func TestGetIPFamilyAndPortFromRef(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

svcIPFamily, servicePort, err := getIPFamilyAndPortFromRef(test.ref, test.svcNsName, services, refPath)
Expand All @@ -313,6 +320,7 @@ func TestGetIPFamilyAndPortFromRef(t *testing.T) {
}

func TestVerifyIPFamily(t *testing.T) {
t.Parallel()
test := []struct {
name string
expErr error
Expand Down Expand Up @@ -377,6 +385,7 @@ func TestVerifyIPFamily(t *testing.T) {

for _, test := range test {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)
err := verifyIPFamily(test.npCfg, test.svcIPFamily)
if test.expErr != nil {
Expand Down Expand Up @@ -748,6 +757,7 @@ func TestAddBackendRefsToRulesTest(t *testing.T) {
}

func TestCreateBackend(t *testing.T) {
t.Parallel()
createService := func(name string) *v1.Service {
return &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -1007,6 +1017,7 @@ func TestCreateBackend(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

alwaysTrueRefGrantResolver := func(_ toResource) bool { return true }
Expand Down Expand Up @@ -1035,6 +1046,7 @@ func TestCreateBackend(t *testing.T) {
}

func TestGetServicePort(t *testing.T) {
t.Parallel()
svc := &v1.Service{
Spec: v1.ServiceSpec{
Ports: []v1.ServicePort{
Expand Down Expand Up @@ -1065,6 +1077,7 @@ func TestGetServicePort(t *testing.T) {
}

func TestValidateBackendTLSPolicyMatchingAllBackends(t *testing.T) {
t.Parallel()
getBtp := func(name, caCertName string) *BackendTLSPolicy {
return &BackendTLSPolicy{
Source: &v1alpha3.BackendTLSPolicy{
Expand Down Expand Up @@ -1156,6 +1169,7 @@ func TestValidateBackendTLSPolicyMatchingAllBackends(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

cond := validateBackendTLSPolicyMatchingAllBackends(test.backendRefs)
Expand All @@ -1166,6 +1180,7 @@ func TestValidateBackendTLSPolicyMatchingAllBackends(t *testing.T) {
}

func TestFindBackendTLSPolicyForService(t *testing.T) {
t.Parallel()
oldCreationTimestamp := metav1.Now()
newCreationTimestamp := metav1.Now()
getBtp := func(name string, timestamp metav1.Time) *BackendTLSPolicy {
Expand Down Expand Up @@ -1231,6 +1246,7 @@ func TestFindBackendTLSPolicyForService(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

btp, err := findBackendTLSPolicyForService(test.backendTLSPolicies, ref.Namespace, string(ref.Name), "test")
Expand All @@ -1242,6 +1258,7 @@ func TestFindBackendTLSPolicyForService(t *testing.T) {
}

func TestGetRefGrantFromResourceForRoute(t *testing.T) {
t.Parallel()
tests := []struct {
name string
routeType RouteType
Expand All @@ -1264,13 +1281,15 @@ func TestGetRefGrantFromResourceForRoute(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)
g.Expect(getRefGrantFromResourceForRoute(test.routeType, test.ns)).To(Equal(test.expFromResource))
})
}
}

func TestGetRefGrantFromResourceForRoute_Panics(t *testing.T) {
t.Parallel()
g := NewWithT(t)

get := func() {
Expand Down
2 changes: 2 additions & 0 deletions internal/mode/static/state/graph/backend_tls_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
)

func TestProcessBackendTLSPoliciesEmpty(t *testing.T) {
t.Parallel()
backendTLSPolicies := map[types.NamespacedName]*v1alpha3.BackendTLSPolicy{
{Namespace: "test", Name: "tls-policy"}: {
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -71,6 +72,7 @@ func TestProcessBackendTLSPoliciesEmpty(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

processed := processBackendTLSPolicies(test.backendTLSPolicies, nil, "test", test.gateway)
Expand Down
2 changes: 2 additions & 0 deletions internal/mode/static/state/graph/configmaps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ UdxohGqleWFMQ3UNLOvc9Fk+q72ryg==
)

func TestValidateCA(t *testing.T) {
t.Parallel()
base64Data := make([]byte, base64.StdEncoding.EncodedLen(len(caBlock)))
base64.StdEncoding.Encode(base64Data, []byte(caBlock))

Expand Down Expand Up @@ -120,6 +121,7 @@ func TestValidateCA(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

err := validateCA(test.data)
Expand Down
4 changes: 4 additions & 0 deletions internal/mode/static/state/graph/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
)

func TestProcessedGatewaysGetAllNsNames(t *testing.T) {
t.Parallel()
winner := &v1.Gateway{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test",
Expand Down Expand Up @@ -58,6 +59,7 @@ func TestProcessedGatewaysGetAllNsNames(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)
result := test.gws.GetAllNsNames()
g.Expect(result).To(Equal(test.expected))
Expand All @@ -66,6 +68,7 @@ func TestProcessedGatewaysGetAllNsNames(t *testing.T) {
}

func TestProcessGateways(t *testing.T) {
t.Parallel()
const gcName = "test-gc"

winner := &v1.Gateway{
Expand Down Expand Up @@ -133,6 +136,7 @@ func TestProcessGateways(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)
result := processGateways(test.gws, gcName)
g.Expect(helpers.Diff(test.expected, result)).To(BeEmpty())
Expand Down
3 changes: 3 additions & 0 deletions internal/mode/static/state/graph/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,7 @@ func TestIsReferenced(t *testing.T) {
}

func TestIsNGFPolicyRelevant(t *testing.T) {
t.Parallel()
policyGVK := schema.GroupVersionKind{Kind: "MyKind"}
existingPolicyNsName := types.NamespacedName{Namespace: "test", Name: "pol"}

Expand Down Expand Up @@ -1324,6 +1325,7 @@ func TestIsNGFPolicyRelevant(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

relevant := test.graph.IsNGFPolicyRelevant(test.policy, policyGVK, test.nsname)
Expand All @@ -1333,6 +1335,7 @@ func TestIsNGFPolicyRelevant(t *testing.T) {
}

func TestIsNGFPolicyRelevantPanics(t *testing.T) {
t.Parallel()
g := NewWithT(t)
graph := &Graph{}
nsname := types.NamespacedName{Namespace: "test", Name: "pol"}
Expand Down
6 changes: 0 additions & 6 deletions internal/mode/static/state/graph/reference_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

func TestReferenceGrantResolver(t *testing.T) {
t.Parallel()

gwNs := "gw-ns"
secretNsName := types.NamespacedName{Namespace: "test", Name: "certificate"}

Expand Down Expand Up @@ -164,7 +163,6 @@ func TestReferenceGrantResolver(t *testing.T) {
for _, test := range tests {
t.Run(test.msg, func(t *testing.T) {
t.Parallel()

g := NewWithT(t)

g.Expect(resolver.refAllowed(test.to, test.from)).To(Equal(test.allowed))
Expand All @@ -174,7 +172,6 @@ func TestReferenceGrantResolver(t *testing.T) {

func TestToSecret(t *testing.T) {
t.Parallel()

ref := toSecret(types.NamespacedName{Namespace: "ns", Name: "secret"})

exp := toResource{
Expand All @@ -189,7 +186,6 @@ func TestToSecret(t *testing.T) {

func TestToService(t *testing.T) {
t.Parallel()

ref := toService(types.NamespacedName{Namespace: "ns", Name: "service"})

exp := toResource{
Expand All @@ -204,7 +200,6 @@ func TestToService(t *testing.T) {

func TestFromGateway(t *testing.T) {
t.Parallel()

ref := fromGateway("ns")

exp := fromResource{
Expand All @@ -219,7 +214,6 @@ func TestFromGateway(t *testing.T) {

func TestFromHTTPRoute(t *testing.T) {
t.Parallel()

ref := fromHTTPRoute("ns")

exp := fromResource{
Expand Down
Loading
Loading