Skip to content

Commit 21e0bad

Browse files
authored
Run tests in internal/framework in parallel (1) (#2362)
1 parent 0ced21f commit 21e0bad

File tree

10 files changed

+24
-6
lines changed

10 files changed

+24
-6
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989
.github/.cache/buster-for-unit-tests
9090
9191
- name: Run Tests
92-
run: make unit-test
92+
run: make unit-test CI=true
9393

9494
- name: Upload coverage reports to Codecov
9595
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ ifneq (,$(findstring plus,$(MAKECMDGOALS)))
4343
PLUS_ENABLED = true
4444
endif
4545

46+
ifeq ($(CI),true)
47+
GITHUB_OUTPUT := --github-output
48+
endif
49+
4650
.PHONY: help
4751
help: Makefile ## Display this help
4852
@grep -hE '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "; printf "Usage:\n\n make \033[36m<target>\033[0m [VARIABLE=value...]\n\nTargets:\n\n"}; {printf " \033[36m%-30s\033[0m %s\n", $$1, $$2}'
@@ -182,7 +186,7 @@ lint: check-golangci-lint ## Run golangci-lint against code
182186
unit-test: ## Run unit tests for the go code
183187
# We have to run the tests in the cmd package using `go test` because of a bug with the CLI library cobra. See https://github.com/spf13/cobra/issues/2104.
184188
go test -buildvcs ./cmd/... -race -shuffle=on -coverprofile=cmd-coverage.out -covermode=atomic
185-
go run github.com/onsi/ginkgo/v2/ginkgo --randomize-all --randomize-suites --race --keep-going --fail-on-pending --trace --covermode=atomic --coverprofile=coverage.out -r internal
189+
go run github.com/onsi/ginkgo/v2/ginkgo --randomize-all --randomize-suites --race --keep-going --fail-on-pending --trace --covermode=atomic --coverprofile=coverage.out --force-newlines $(GITHUB_OUTPUT) -p -v -r internal
186190
go tool cover -html=coverage.out -o cover.html
187191
go tool cover -html=cmd-coverage.out -o cmd-cover.html
188192

internal/framework/conditions/conditions_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
)
99

1010
func TestDeduplicateConditions(t *testing.T) {
11+
t.Parallel()
1112
conds := []Condition{
1213
{
1314
Type: "Type1",
@@ -61,6 +62,7 @@ func TestDeduplicateConditions(t *testing.T) {
6162
}
6263

6364
func TestConvertConditions(t *testing.T) {
65+
t.Parallel()
6466
conds := []Condition{
6567
{
6668
Type: "Type1",

internal/framework/events/events_suite_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
)
99

1010
func TestEvents(t *testing.T) {
11+
t.Parallel()
1112
RegisterFailHandler(Fail)
1213
RunSpecs(t, "Events Suite")
1314
}

internal/framework/events/events_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
)
99

1010
func TestEventLoop_SwapBatches(t *testing.T) {
11+
t.Parallel()
1112
g := NewWithT(t)
1213
eventLoop := NewEventLoop(nil, zap.New(), nil, nil)
1314

internal/framework/gatewayclass/validate_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
)
1414

1515
func TestValidateCRDVersions(t *testing.T) {
16+
t.Parallel()
1617
createCRDMetadata := func(version string) *metav1.PartialObjectMetadata {
1718
return &metav1.PartialObjectMetadata{
1819
ObjectMeta: metav1.ObjectMeta{
@@ -113,7 +114,9 @@ func TestValidateCRDVersions(t *testing.T) {
113114
}
114115

115116
for _, test := range tests {
117+
test := test
116118
t.Run(test.name, func(t *testing.T) {
119+
t.Parallel()
117120
g := NewWithT(t)
118121

119122
conds, valid := gatewayclass.ValidateCRDVersions(test.crds)

internal/framework/helpers/helpers_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
)
1414

1515
func TestMustCastObject(t *testing.T) {
16+
t.Parallel()
1617
g := NewWithT(t)
1718

1819
var obj client.Object = &gatewayv1.Gateway{}
@@ -27,6 +28,7 @@ func TestMustCastObject(t *testing.T) {
2728
}
2829

2930
func TestEqualPointers(t *testing.T) {
31+
t.Parallel()
3032
tests := []struct {
3133
p1 *string
3234
p2 *string
@@ -78,7 +80,9 @@ func TestEqualPointers(t *testing.T) {
7880
}
7981

8082
for _, test := range tests {
83+
test := test
8184
t.Run(test.name, func(t *testing.T) {
85+
t.Parallel()
8286
g := NewWithT(t)
8387

8488
val := helpers.EqualPointers(test.p1, test.p2)
@@ -88,6 +92,7 @@ func TestEqualPointers(t *testing.T) {
8892
}
8993

9094
func TestMustExecuteTemplate(t *testing.T) {
95+
t.Parallel()
9196
g := NewWithT(t)
9297

9398
tmpl := template.Must(template.New("test").Parse(`Hello {{.}}`))
@@ -96,6 +101,7 @@ func TestMustExecuteTemplate(t *testing.T) {
96101
}
97102

98103
func TestMustExecuteTemplatePanics(t *testing.T) {
104+
t.Parallel()
99105
g := NewWithT(t)
100106

101107
execute := func() {

internal/framework/runnables/cronjob_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
)
1111

1212
func TestCronJob(t *testing.T) {
13+
t.Parallel()
1314
g := NewWithT(t)
1415

1516
readyChannel := make(chan struct{})
@@ -50,6 +51,7 @@ func TestCronJob(t *testing.T) {
5051
}
5152

5253
func TestCronJob_ContextCanceled(t *testing.T) {
54+
t.Parallel()
5355
g := NewWithT(t)
5456

5557
readyChannel := make(chan struct{})

internal/framework/runnables/runnables_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@ import (
88
)
99

1010
func TestLeader(t *testing.T) {
11+
t.Parallel()
1112
leader := &Leader{}
1213

1314
g := NewWithT(t)
1415
g.Expect(leader.NeedLeaderElection()).To(BeTrue())
1516
}
1617

1718
func TestLeaderOrNonLeader(t *testing.T) {
19+
t.Parallel()
1820
leaderOrNonLeader := &LeaderOrNonLeader{}
1921

2022
g := NewWithT(t)
2123
g.Expect(leaderOrNonLeader.NeedLeaderElection()).To(BeFalse())
2224
}
2325

2426
func TestEnableAfterBecameLeader(t *testing.T) {
27+
t.Parallel()
2528
enabled := false
2629
enableAfterBecameLeader := NewEnableAfterBecameLeader(func(_ context.Context) {
2730
enabled = true

tests/Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ ifneq ($(GINKGO_LABEL),)
2929
override GINKGO_FLAGS += --label-filter "$(GINKGO_LABEL)"
3030
endif
3131

32-
ifeq ($(CI),true)
33-
GITHUB_OUTPUT := --github-output
34-
endif
35-
3632
.PHONY: update-go-modules
3733
update-go-modules: ## Update the gateway-api go modules to latest main version
3834
go get -u sigs.k8s.io/gateway-api@main

0 commit comments

Comments
 (0)