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

Run tests in parallel #3910

Merged
merged 4 commits into from
May 18, 2023
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
10 changes: 10 additions & 0 deletions internal/k8s/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func createTestConfiguration() *Configuration {
}

func TestAddIngressForRegularIngress(t *testing.T) {
t.Parallel()
configuration := createTestConfiguration()

// no problems are expected for all cases
Expand Down Expand Up @@ -216,6 +217,7 @@ func TestAddIngressForRegularIngress(t *testing.T) {
}

func TestAddInvalidIngress(t *testing.T) {
t.Parallel()
configuration := createTestConfiguration()

ing := createTestIngress("ingress", "foo.example.com", "foo.example.com")
Expand Down Expand Up @@ -3072,6 +3074,7 @@ func TestChooseObjectMetaWinner(t *testing.T) {
}

func TestSquashResourceChanges(t *testing.T) {
t.Parallel()
ingConfig := &IngressConfiguration{
Ingress: createTestIngress("test", "foo.example.com"),
}
Expand Down Expand Up @@ -3256,6 +3259,7 @@ func (rc *testReferenceChecker) IsReferencedByTransportServer(namespace string,
}

func TestFindResourcesForResourceReference(t *testing.T) {
t.Parallel()
regularIng := createTestIngress("regular-ingress", "foo.example.com")
master := createTestIngressMaster("master-ingress", "bar.example.com")
minion := createTestIngressMinion("minion-ingress", "bar.example.com", "/")
Expand Down Expand Up @@ -3379,6 +3383,7 @@ func TestFindResourcesForResourceReference(t *testing.T) {
}

func TestGetResources(t *testing.T) {
t.Parallel()
ing := createTestIngress("ingress", "foo.example.com", "bar.example.com")
vs := createTestVirtualServer("virtualserver", "qwe.example.com")
passTS := createTestTLSPassthroughTransportServer("transportserver", "abc.example.com")
Expand Down Expand Up @@ -3446,6 +3451,7 @@ func TestGetResources(t *testing.T) {
}

func TestGetTransportServerMetrics(t *testing.T) {
t.Parallel()
tsPass := createTestTLSPassthroughTransportServer("transportserver", "abc.example.com")
tsTCP := createTestTransportServer("transportserver-tcp", "tcp-7777", "TCP")
tsUDP := createTestTransportServer("transportserver-udp", "udp-7777", "UDP")
Expand Down Expand Up @@ -3544,6 +3550,7 @@ func TestGetTransportServerMetrics(t *testing.T) {
}

func TestIsEqualForIngressConfigurations(t *testing.T) {
t.Parallel()
regularIng := createTestIngress("regular-ingress", "foo.example.com")

ingConfigWithInvalidHost := NewRegularIngressConfiguration(regularIng)
Expand Down Expand Up @@ -3638,6 +3645,7 @@ func TestIsEqualForIngressConfigurations(t *testing.T) {
}

func TestIsEqualForVirtualServers(t *testing.T) {
t.Parallel()
vs := createTestVirtualServerWithRoutes(
"virtualserver",
"foo.example.com",
Expand Down Expand Up @@ -3696,6 +3704,7 @@ func TestIsEqualForVirtualServers(t *testing.T) {
}

func TestIsEqualForDifferentResources(t *testing.T) {
t.Parallel()
ingConfig := NewRegularIngressConfiguration(createTestIngress("ingress", "foo.example.com"))
vsConfig := NewVirtualServerConfiguration(createTestVirtualServer("virtualserver", "bar.example.com"), []*conf_v1.VirtualServerRoute{}, []string{})

Expand All @@ -3706,6 +3715,7 @@ func TestIsEqualForDifferentResources(t *testing.T) {
}

func TestCompareConfigurationProblems(t *testing.T) {
t.Parallel()
tests := []struct {
problem1 *ConfigurationProblem
problem2 *ConfigurationProblem
Expand Down
36 changes: 36 additions & 0 deletions internal/k8s/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
)

func TestHasCorrectIngressClass(t *testing.T) {
t.Parallel()
ingressClass := "ing-ctrl"
incorrectIngressClass := "gce"
emptyClass := ""
Expand Down Expand Up @@ -172,6 +173,7 @@ func deepCopyWithIngressClass(obj interface{}, class string) interface{} {
}

func TestIngressClassForCustomResources(t *testing.T) {
t.Parallel()
ctrl := &LoadBalancerController{
ingressClass: "nginx",
}
Expand Down Expand Up @@ -221,6 +223,7 @@ func TestIngressClassForCustomResources(t *testing.T) {
}

func TestComparePorts(t *testing.T) {
t.Parallel()
scenarios := []struct {
sp api_v1.ServicePort
cp api_v1.ContainerPort
Expand Down Expand Up @@ -314,6 +317,7 @@ func TestComparePorts(t *testing.T) {
}

func TestFindProbeForPods(t *testing.T) {
t.Parallel()
pods := []*api_v1.Pod{
{
Spec: api_v1.PodSpec{
Expand Down Expand Up @@ -404,6 +408,7 @@ func TestFindProbeForPods(t *testing.T) {
}

func TestGetServicePortForIngressPort(t *testing.T) {
t.Parallel()
fakeClient := fake.NewSimpleClientset()
cnf := configs.NewConfigurator(&nginx.LocalManager{}, &configs.StaticConfigParams{}, &configs.ConfigParams{}, &version1.TemplateExecutor{}, &version2.TemplateExecutor{}, false, false, nil, false, nil, false)
lbc := LoadBalancerController{
Expand Down Expand Up @@ -462,6 +467,7 @@ func TestGetServicePortForIngressPort(t *testing.T) {
}

func TestFormatWarningsMessages(t *testing.T) {
t.Parallel()
warnings := []string{"Test warning", "Test warning 2"}

expected := "Test warning; Test warning 2"
Expand All @@ -473,6 +479,7 @@ func TestFormatWarningsMessages(t *testing.T) {
}

func TestGetEndpointsFromEndpointSlices_DuplicateEndpointsInOneEndpointSlice(t *testing.T) {
t.Parallel()
endpointPort := int32(8080)

lbc := LoadBalancerController{
Expand Down Expand Up @@ -561,6 +568,7 @@ func TestGetEndpointsFromEndpointSlices_DuplicateEndpointsInOneEndpointSlice(t *
}

func TestGetEndpointsFromEndpointSlices_TwoDifferentEndpointsInOnEndpointSlice(t *testing.T) {
t.Parallel()
endpointPort := int32(8080)

lbc := LoadBalancerController{
Expand Down Expand Up @@ -651,6 +659,7 @@ func TestGetEndpointsFromEndpointSlices_TwoDifferentEndpointsInOnEndpointSlice(t
}

func TestGetEndpointsFromEndpointSlices_DuplicateEndpointsAcrossTwoEndpointSlices(t *testing.T) {
t.Parallel()
endpointPort := int32(8080)

lbc := LoadBalancerController{
Expand Down Expand Up @@ -770,6 +779,7 @@ func TestGetEndpointsFromEndpointSlices_DuplicateEndpointsAcrossTwoEndpointSlice
}

func TestGetEndpointsFromEndpointSlices_TwoDifferentEndpointsInOnEndpointSliceOneEndpointNotReady(t *testing.T) {
t.Parallel()
endpointPort := int32(8080)

lbc := LoadBalancerController{
Expand Down Expand Up @@ -858,6 +868,7 @@ func TestGetEndpointsFromEndpointSlices_TwoDifferentEndpointsInOnEndpointSliceOn
}

func TestGetEndpointsFromEndpointSlices_TwoDifferentEndpointsAcrossTwoEndpointSlicesOneEndpointNotReady(t *testing.T) {
t.Parallel()
endpointPort := int32(8080)

lbc := LoadBalancerController{
Expand Down Expand Up @@ -956,6 +967,7 @@ func TestGetEndpointsFromEndpointSlices_TwoDifferentEndpointsAcrossTwoEndpointSl
}

func TestGetEndpointsFromEndpointSlices_ErrorsOnInvalidTargetPort(t *testing.T) {
t.Parallel()
endpointPort := int32(8080)

lbc := LoadBalancerController{
Expand Down Expand Up @@ -1027,6 +1039,7 @@ func TestGetEndpointsFromEndpointSlices_ErrorsOnInvalidTargetPort(t *testing.T)
}

func TestGetEndpointsFromEndpointSlices_ErrorsOnNoEndpointSlicesFound(t *testing.T) {
t.Parallel()
lbc := LoadBalancerController{
isNginxPlus: true,
}
Expand Down Expand Up @@ -1076,6 +1089,7 @@ func TestGetEndpointsFromEndpointSlices_ErrorsOnNoEndpointSlicesFound(t *testing
}

func TestGetEndpointSlicesBySubselectedPods_FindOnePodInOneEndpointSlice(t *testing.T) {
t.Parallel()
endpointPort := int32(8080)
endpointReady := true
boolPointer := func(b bool) *bool { return &b }
Expand Down Expand Up @@ -1148,6 +1162,7 @@ func TestGetEndpointSlicesBySubselectedPods_FindOnePodInOneEndpointSlice(t *test
}

func TestGetEndpointSlicesBySubselectedPods_FindOnePodInTwoEndpointSlicesWithDuplicateEndpoints(t *testing.T) {
t.Parallel()
endpointPort := int32(8080)
endpointReady := true
boolPointer := func(b bool) *bool { return &b }
Expand Down Expand Up @@ -1237,6 +1252,7 @@ func TestGetEndpointSlicesBySubselectedPods_FindOnePodInTwoEndpointSlicesWithDup
}

func TestGetEndpointSlicesBySubselectedPods_FindTwoPodsInOneEndpointSlice(t *testing.T) {
t.Parallel()
endpointPort := int32(8080)
endpointReady := true
boolPointer := func(b bool) *bool { return &b }
Expand Down Expand Up @@ -1338,6 +1354,7 @@ func TestGetEndpointSlicesBySubselectedPods_FindTwoPodsInOneEndpointSlice(t *tes
}

func TestGetEndpointSlicesBySubselectedPods_FindTwoPodsInTwoEndpointSlices(t *testing.T) {
t.Parallel()
endpointPort := int32(8080)
endpointReady := true
boolPointer := func(b bool) *bool { return &b }
Expand Down Expand Up @@ -1448,6 +1465,7 @@ func TestGetEndpointSlicesBySubselectedPods_FindTwoPodsInTwoEndpointSlices(t *te
}

func TestGetEndpointSlicesBySubselectedPods_FindOnePodEndpointInOneEndpointSliceWithOneEndpointNotReady(t *testing.T) {
t.Parallel()
endpointPort := int32(8080)
endpointReadyTrue := true
endpointReadyFalse := false
Expand Down Expand Up @@ -1543,6 +1561,7 @@ func TestGetEndpointSlicesBySubselectedPods_FindOnePodEndpointInOneEndpointSlice
}

func TestGetEndpointSlicesBySubselectedPods_FindOnePodEndpointInTwoEndpointSlicesWithOneEndpointNotReady(t *testing.T) {
t.Parallel()
endpointPort := int32(8080)
endpointReadyTrue := true
endpointReadyFalse := false
Expand Down Expand Up @@ -1647,6 +1666,7 @@ func TestGetEndpointSlicesBySubselectedPods_FindOnePodEndpointInTwoEndpointSlice
}

func TestGetEndpointSlicesBySubselectedPods_FindNoPods(t *testing.T) {
t.Parallel()
endpointPort := int32(8080)
endpointReady := true
boolPointer := func(b bool) *bool { return &b }
Expand Down Expand Up @@ -1711,6 +1731,7 @@ func TestGetEndpointSlicesBySubselectedPods_FindNoPods(t *testing.T) {
}

func TestGetEndpointSlicesBySubselectedPods_TargetPortMismatch(t *testing.T) {
t.Parallel()
endpointPort := int32(8080)

boolPointer := func(b bool) *bool { return &b }
Expand Down Expand Up @@ -1788,6 +1809,7 @@ func unorderedEqual(got, want []podEndpoint) bool {
}

func TestGetStatusFromEventTitle(t *testing.T) {
t.Parallel()
tests := []struct {
eventTitle string
expected string
Expand Down Expand Up @@ -1847,6 +1869,7 @@ func TestGetStatusFromEventTitle(t *testing.T) {
}

func TestGetPolicies(t *testing.T) {
t.Parallel()
validPolicy := &conf_v1.Policy{
ObjectMeta: meta_v1.ObjectMeta{
Name: "valid-policy",
Expand Down Expand Up @@ -1946,6 +1969,7 @@ func TestGetPolicies(t *testing.T) {
}

func TestCreatePolicyMap(t *testing.T) {
t.Parallel()
policies := []*conf_v1.Policy{
{
ObjectMeta: meta_v1.ObjectMeta{
Expand Down Expand Up @@ -2001,6 +2025,7 @@ func TestCreatePolicyMap(t *testing.T) {
}

func TestGetPodOwnerTypeAndName(t *testing.T) {
t.Parallel()
tests := []struct {
desc string
expType string
Expand Down Expand Up @@ -2144,6 +2169,7 @@ func (t *testResource) String() string {
}

func TestRemoveDuplicateResources(t *testing.T) {
t.Parallel()
tests := []struct {
resources []Resource
expected []Resource
Expand Down Expand Up @@ -2182,6 +2208,7 @@ func TestRemoveDuplicateResources(t *testing.T) {
}

func TestFindPoliciesForSecret(t *testing.T) {
t.Parallel()
jwtPol1 := &conf_v1.Policy{
ObjectMeta: meta_v1.ObjectMeta{
Name: "jwt-policy",
Expand Down Expand Up @@ -2398,6 +2425,7 @@ func errorComparer(e1, e2 error) bool {
}

func TestAddJWTSecrets(t *testing.T) {
t.Parallel()
invalidErr := errors.New("invalid")
validJWKSecret := &api_v1.Secret{
ObjectMeta: meta_v1.ObjectMeta{
Expand Down Expand Up @@ -2542,6 +2570,7 @@ func TestAddJWTSecrets(t *testing.T) {
}

func TestAddBasicSecrets(t *testing.T) {
t.Parallel()
invalidErr := errors.New("invalid")
validBasicSecret := &api_v1.Secret{
ObjectMeta: meta_v1.ObjectMeta{
Expand Down Expand Up @@ -2666,6 +2695,7 @@ func TestAddBasicSecrets(t *testing.T) {
}

func TestAddIngressMTLSSecret(t *testing.T) {
t.Parallel()
invalidErr := errors.New("invalid")
validSecret := &api_v1.Secret{
ObjectMeta: meta_v1.ObjectMeta{
Expand Down Expand Up @@ -2788,6 +2818,7 @@ func TestAddIngressMTLSSecret(t *testing.T) {
}

func TestAddEgressMTLSSecrets(t *testing.T) {
t.Parallel()
invalidErr := errors.New("invalid")
validMTLSSecret := &api_v1.Secret{
ObjectMeta: meta_v1.ObjectMeta{
Expand Down Expand Up @@ -3005,6 +3036,7 @@ func TestAddEgressMTLSSecrets(t *testing.T) {
}

func TestAddOidcSecret(t *testing.T) {
t.Parallel()
invalidErr := errors.New("invalid")
validSecret := &api_v1.Secret{
ObjectMeta: meta_v1.ObjectMeta{
Expand Down Expand Up @@ -3128,6 +3160,7 @@ func TestAddOidcSecret(t *testing.T) {
}

func TestAddWAFPolicyRefs(t *testing.T) {
t.Parallel()
apPol := &unstructured.Unstructured{
Object: map[string]interface{}{
"metadata": map[string]interface{}{
Expand Down Expand Up @@ -3358,6 +3391,7 @@ func TestAddWAFPolicyRefs(t *testing.T) {
}

func TestGetWAFPoliciesForAppProtectPolicy(t *testing.T) {
t.Parallel()
apPol := &conf_v1.Policy{
Spec: conf_v1.PolicySpec{
WAF: &conf_v1.WAF{
Expand Down Expand Up @@ -3435,6 +3469,7 @@ func TestGetWAFPoliciesForAppProtectPolicy(t *testing.T) {
}

func TestGetWAFPoliciesForAppProtectLogConf(t *testing.T) {
t.Parallel()
logConf := &conf_v1.Policy{
Spec: conf_v1.PolicySpec{
WAF: &conf_v1.WAF{
Expand Down Expand Up @@ -3541,6 +3576,7 @@ func TestGetWAFPoliciesForAppProtectLogConf(t *testing.T) {
}

func TestPreSyncSecrets(t *testing.T) {
t.Parallel()
secretLister := &cache.FakeCustomStore{
ListFunc: func() []interface{} {
return []interface{}{
Expand Down
2 changes: 2 additions & 0 deletions internal/k8s/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

func TestHasServicePortChanges(t *testing.T) {
t.Parallel()
cases := []struct {
a []v1.ServicePort
b []v1.ServicePort
Expand Down Expand Up @@ -158,6 +159,7 @@ func TestHasServicePortChanges(t *testing.T) {
}

func TestAreResourcesDifferent(t *testing.T) {
t.Parallel()
tests := []struct {
oldR, newR *unstructured.Unstructured
expected bool
Expand Down
Loading