Skip to content

Commit

Permalink
Run tests in parallel (#2537)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacome authored Sep 12, 2024
1 parent 74724a6 commit ea7ef87
Show file tree
Hide file tree
Showing 22 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/mode/provisioner/provisioner_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

func TestProvisioner(t *testing.T) {
t.Parallel()
RegisterFailHandler(Fail)
RunSpecs(t, "Provisioner Suite")
}
2 changes: 2 additions & 0 deletions internal/mode/static/config_updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func TestUpdateControlPlane(t *testing.T) {
}

func TestValidateLogLevel(t *testing.T) {
t.Parallel()
validLevels := []ngfAPI.ControllerLogLevel{
ngfAPI.ControllerLogLevelError,
ngfAPI.ControllerLogLevelInfo,
Expand All @@ -125,6 +126,7 @@ func TestValidateLogLevel(t *testing.T) {

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

g.Expect(validateLogLevel(level)).ToNot(Succeed())
Expand Down
1 change: 1 addition & 0 deletions internal/mode/static/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

func TestReadyCheck(t *testing.T) {
t.Parallel()
g := NewWithT(t)
nginxChecker := newNginxConfiguredOnStartChecker()
g.Expect(nginxChecker.readyCheck(nil)).ToNot(Succeed())
Expand Down
3 changes: 3 additions & 0 deletions internal/mode/static/log_level_setters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

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

logr1 := &staticfakes.FakeLogLevelSetter{}
Expand Down Expand Up @@ -41,6 +42,7 @@ func TestMultiLogLevelSetter_SetLevel(t *testing.T) {
}

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

zapSetter := newZapLogLevelSetter(zap.NewAtomicLevel())
Expand All @@ -58,6 +60,7 @@ func TestZapLogLevelSetter_SetLevel(t *testing.T) {
}

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

logger, err := newLeveledPrometheusLogger()
Expand Down
4 changes: 4 additions & 0 deletions internal/mode/static/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
)

func TestPrepareFirstEventBatchPreparerArgs(t *testing.T) {
t.Parallel()
const gcName = "nginx"

partialObjectMetadataList := &metav1.PartialObjectMetadataList{}
Expand Down Expand Up @@ -117,6 +118,7 @@ func TestPrepareFirstEventBatchPreparerArgs(t *testing.T) {

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

objects, objectLists := prepareFirstEventBatchPreparerArgs(gcName, test.gwNsName, test.experimentalEnabled)
Expand All @@ -128,6 +130,7 @@ func TestPrepareFirstEventBatchPreparerArgs(t *testing.T) {
}

func TestGetMetricsOptions(t *testing.T) {
t.Parallel()
tests := []struct {
name string
expectedOptions metricsserver.Options
Expand Down Expand Up @@ -166,6 +169,7 @@ func TestGetMetricsOptions(t *testing.T) {

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

metricsServerOptions := getMetricsOptions(test.metricsConfig)
Expand Down
1 change: 1 addition & 0 deletions internal/mode/static/nginx/file/file_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

func TestFile(t *testing.T) {
t.Parallel()
RegisterFailHandler(Fail)
RunSpecs(t, "File Suite")
}
3 changes: 3 additions & 0 deletions internal/mode/static/nginx/file/folders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func writeFile(t *testing.T, name string, data []byte) {
}

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

tempDir := t.TempDir()
Expand All @@ -41,6 +42,7 @@ func TestClearFoldersRemoves(t *testing.T) {
}

func TestClearFoldersFails(t *testing.T) {
t.Parallel()
files := []string{"file"}

testErr := errors.New("test error")
Expand Down Expand Up @@ -78,6 +80,7 @@ func TestClearFoldersFails(t *testing.T) {

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

removedFiles, err := file.ClearFolders(test.fileMgr, files)
Expand Down
2 changes: 2 additions & 0 deletions internal/mode/static/nginx/runtime/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ var _ = Describe("NGINX Runtime Manager", func() {
})

func TestFindMainProcess(t *testing.T) {
t.Parallel()
readFileFuncGen := func(content []byte) runtime.ReadFileFunc {
return func(name string) ([]byte, error) {
if name != runtime.PidFile {
Expand Down Expand Up @@ -311,6 +312,7 @@ func TestFindMainProcess(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)
p := runtime.NewProcessHandlerImpl(
test.readFile,
Expand Down
1 change: 1 addition & 0 deletions internal/mode/static/nginx/runtime/runtime_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

func TestRuntime(t *testing.T) {
t.Parallel()
RegisterFailHandler(Fail)
RunSpecs(t, "Runtime Suite")
}
4 changes: 4 additions & 0 deletions internal/mode/static/nginx/runtime/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func getTestHTTPClient() *http.Client {
}

func TestVerifyClient(t *testing.T) {
t.Parallel()
c := VerifyClient{
client: getTestHTTPClient(),
timeout: 25 * time.Millisecond,
Expand Down Expand Up @@ -87,6 +88,7 @@ func TestVerifyClient(t *testing.T) {

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

err := c.WaitForCorrectVersion(test.ctx, test.expectedVersion, "/childfile", []byte("1 2 3"), test.readFile)
Expand All @@ -101,6 +103,7 @@ func TestVerifyClient(t *testing.T) {
}

func TestEnsureNewNginxWorkers(t *testing.T) {
t.Parallel()
previousContents := []byte("1 2 3")
newContents := []byte("4 5 6")

Expand Down Expand Up @@ -163,6 +166,7 @@ func TestEnsureNewNginxWorkers(t *testing.T) {

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

err := ensureNewNginxWorkers(
Expand Down
4 changes: 4 additions & 0 deletions internal/mode/static/sort/sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

func TestLessObjectMeta(t *testing.T) {
t.Parallel()
before := metav1.Now()
later := metav1.NewTime(before.Add(1 * time.Second))

Expand Down Expand Up @@ -80,6 +81,7 @@ func TestLessObjectMeta(t *testing.T) {

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

result := LessObjectMeta(test.meta1, test.meta2)
Expand All @@ -92,6 +94,7 @@ func TestLessObjectMeta(t *testing.T) {
}

func TestLessClientObject(t *testing.T) {
t.Parallel()
before := metav1.Now()
later := metav1.NewTime(before.Add(1 * time.Second))

Expand Down Expand Up @@ -177,6 +180,7 @@ func TestLessClientObject(t *testing.T) {

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

result := LessClientObject(test.obj1, test.obj2)
Expand Down
1 change: 1 addition & 0 deletions internal/mode/static/static_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

func TestStatic(t *testing.T) {
t.Parallel()
RegisterFailHandler(Fail)
RunSpecs(t, "Static Suite")
}
14 changes: 14 additions & 0 deletions internal/mode/static/status/prepare_requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ var (
)

func TestBuildHTTPRouteStatuses(t *testing.T) {
t.Parallel()
hrValid := &v1.HTTPRoute{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test",
Expand Down Expand Up @@ -291,6 +292,7 @@ func TestBuildHTTPRouteStatuses(t *testing.T) {
}

func TestBuildGRPCRouteStatuses(t *testing.T) {
t.Parallel()
grValid := &v1.GRPCRoute{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test",
Expand Down Expand Up @@ -369,6 +371,7 @@ func TestBuildGRPCRouteStatuses(t *testing.T) {
}

func TestBuildTLSRouteStatuses(t *testing.T) {
t.Parallel()
trValid := &v1alpha2.TLSRoute{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test",
Expand Down Expand Up @@ -445,6 +448,7 @@ func TestBuildTLSRouteStatuses(t *testing.T) {
}

func TestBuildRouteStatusesNginxErr(t *testing.T) {
t.Parallel()
const gatewayCtlrName = "controller"

hr1 := &v1.HTTPRoute{
Expand Down Expand Up @@ -546,6 +550,7 @@ func TestBuildRouteStatusesNginxErr(t *testing.T) {
}

func TestBuildGatewayClassStatuses(t *testing.T) {
t.Parallel()
transitionTime := helpers.PrepareTimeForFakeClient(metav1.Now())

tests := []struct {
Expand Down Expand Up @@ -638,6 +643,7 @@ func TestBuildGatewayClassStatuses(t *testing.T) {

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

k8sClient := createK8sClientFor(&v1.GatewayClass{})
Expand Down Expand Up @@ -676,6 +682,7 @@ func TestBuildGatewayClassStatuses(t *testing.T) {
}

func TestBuildGatewayStatuses(t *testing.T) {
t.Parallel()
createGateway := func() *v1.Gateway {
return &v1.Gateway{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -1131,6 +1138,7 @@ func TestBuildGatewayStatuses(t *testing.T) {

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

k8sClient := createK8sClientFor(&v1.Gateway{})
Expand Down Expand Up @@ -1176,6 +1184,7 @@ func TestBuildGatewayStatuses(t *testing.T) {
}

func TestBuildBackendTLSPolicyStatuses(t *testing.T) {
t.Parallel()
const gatewayCtlrName = "controller"

transitionTime := helpers.PrepareTimeForFakeClient(metav1.Now())
Expand Down Expand Up @@ -1357,6 +1366,7 @@ func TestBuildBackendTLSPolicyStatuses(t *testing.T) {

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

k8sClient := createK8sClientFor(&v1alpha3.BackendTLSPolicy{})
Expand Down Expand Up @@ -1386,6 +1396,7 @@ func TestBuildBackendTLSPolicyStatuses(t *testing.T) {
}

func TestBuildNginxGatewayStatus(t *testing.T) {
t.Parallel()
transitionTime := helpers.PrepareTimeForFakeClient(metav1.Now())

tests := []struct {
Expand Down Expand Up @@ -1449,6 +1460,7 @@ func TestBuildNginxGatewayStatus(t *testing.T) {

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

k8sClient := createK8sClientFor(&ngfAPI.NginxGateway{})
Expand Down Expand Up @@ -1479,6 +1491,7 @@ func TestBuildNginxGatewayStatus(t *testing.T) {
}

func TestBuildNGFPolicyStatuses(t *testing.T) {
t.Parallel()
const gatewayCtlrName = "controller"

transitionTime := helpers.PrepareTimeForFakeClient(metav1.Now())
Expand Down Expand Up @@ -1741,6 +1754,7 @@ func TestBuildNGFPolicyStatuses(t *testing.T) {

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

k8sClient := createK8sClientFor(&ngfAPI.ClientSettingsPolicy{})
Expand Down
Loading

0 comments on commit ea7ef87

Please sign in to comment.