Skip to content

Run tests in internal/framework in parallel (1) #2362

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

Merged
merged 2 commits into from
Aug 12, 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
.github/.cache/buster-for-unit-tests

- name: Run Tests
run: make unit-test
run: make unit-test CI=true

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ ifneq (,$(findstring plus,$(MAKECMDGOALS)))
PLUS_ENABLED = true
endif

ifeq ($(CI),true)
GITHUB_OUTPUT := --github-output
endif

.PHONY: help
help: Makefile ## Display this help
@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}'
Expand Down Expand Up @@ -182,7 +186,7 @@ lint: check-golangci-lint ## Run golangci-lint against code
unit-test: ## Run unit tests for the go code
# 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.
go test -buildvcs ./cmd/... -race -shuffle=on -coverprofile=cmd-coverage.out -covermode=atomic
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
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
go tool cover -html=coverage.out -o cover.html
go tool cover -html=cmd-coverage.out -o cmd-cover.html

Expand Down
2 changes: 2 additions & 0 deletions internal/framework/conditions/conditions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

func TestDeduplicateConditions(t *testing.T) {
t.Parallel()
conds := []Condition{
{
Type: "Type1",
Expand Down Expand Up @@ -61,6 +62,7 @@ func TestDeduplicateConditions(t *testing.T) {
}

func TestConvertConditions(t *testing.T) {
t.Parallel()
conds := []Condition{
{
Type: "Type1",
Expand Down
1 change: 1 addition & 0 deletions internal/framework/events/events_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

func TestEvents(t *testing.T) {
t.Parallel()
RegisterFailHandler(Fail)
RunSpecs(t, "Events Suite")
}
1 change: 1 addition & 0 deletions internal/framework/events/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

func TestEventLoop_SwapBatches(t *testing.T) {
t.Parallel()
g := NewWithT(t)
eventLoop := NewEventLoop(nil, zap.New(), nil, nil)

Expand Down
3 changes: 3 additions & 0 deletions internal/framework/gatewayclass/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
)

func TestValidateCRDVersions(t *testing.T) {
t.Parallel()
createCRDMetadata := func(version string) *metav1.PartialObjectMetadata {
return &metav1.PartialObjectMetadata{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -113,7 +114,9 @@ func TestValidateCRDVersions(t *testing.T) {
}

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

conds, valid := gatewayclass.ValidateCRDVersions(test.crds)
Expand Down
6 changes: 6 additions & 0 deletions internal/framework/helpers/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
)

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

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

func TestEqualPointers(t *testing.T) {
t.Parallel()
tests := []struct {
p1 *string
p2 *string
Expand Down Expand Up @@ -78,7 +80,9 @@ func TestEqualPointers(t *testing.T) {
}

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

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

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

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

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

execute := func() {
Expand Down
2 changes: 2 additions & 0 deletions internal/framework/runnables/cronjob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

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

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

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

readyChannel := make(chan struct{})
Expand Down
3 changes: 3 additions & 0 deletions internal/framework/runnables/runnables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@ import (
)

func TestLeader(t *testing.T) {
t.Parallel()
leader := &Leader{}

g := NewWithT(t)
g.Expect(leader.NeedLeaderElection()).To(BeTrue())
}

func TestLeaderOrNonLeader(t *testing.T) {
t.Parallel()
leaderOrNonLeader := &LeaderOrNonLeader{}

g := NewWithT(t)
g.Expect(leaderOrNonLeader.NeedLeaderElection()).To(BeFalse())
}

func TestEnableAfterBecameLeader(t *testing.T) {
t.Parallel()
enabled := false
enableAfterBecameLeader := NewEnableAfterBecameLeader(func(_ context.Context) {
enabled = true
Expand Down
4 changes: 0 additions & 4 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ ifneq ($(GINKGO_LABEL),)
override GINKGO_FLAGS += --label-filter "$(GINKGO_LABEL)"
endif

ifeq ($(CI),true)
GITHUB_OUTPUT := --github-output
endif

.PHONY: update-go-modules
update-go-modules: ## Update the gateway-api go modules to latest main version
go get -u sigs.k8s.io/gateway-api@main
Expand Down
Loading