Skip to content

Commit

Permalink
Run tests in internal/framework in parallel (2) (#2367)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacome authored Aug 14, 2024
1 parent e9b626b commit 2ac3239
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions internal/framework/controller/controller_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

func TestControllers(t *testing.T) {
t.Parallel()
RegisterFailHandler(Fail)
RunSpecs(t, "Controller Suite")
}
3 changes: 3 additions & 0 deletions internal/framework/controller/filter/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

func TestCreateSingleResourceFilter(t *testing.T) {
t.Parallel()
targetNsName := types.NamespacedName{Namespace: "test", Name: "resource"}

g := NewWithT(t)
Expand Down Expand Up @@ -50,7 +51,9 @@ func TestCreateSingleResourceFilter(t *testing.T) {
}

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)
shouldProcess, msg := filter(test.nsname)
g.Expect(shouldProcess).To(Equal(test.expectedShouldProcess))
Expand Down
13 changes: 10 additions & 3 deletions internal/framework/controller/index/endpointslice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

func TestServiceNameIndexFunc(t *testing.T) {
t.Parallel()
testcases := []struct {
msg string
obj client.Object
Expand Down Expand Up @@ -42,13 +43,19 @@ func TestServiceNameIndexFunc(t *testing.T) {
}

for _, tc := range testcases {
g := NewWithT(t)
output := ServiceNameIndexFunc(tc.obj)
g.Expect(output).To(Equal(tc.expOutput))
tc := tc
t.Run(tc.msg, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

output := ServiceNameIndexFunc(tc.obj)
g.Expect(output).To(Equal(tc.expOutput))
})
}
}

func TestServiceNameIndexFuncPanics(t *testing.T) {
t.Parallel()
defer func() {
g := NewWithT(t)
g.Expect(recover()).ToNot(BeNil())
Expand Down
6 changes: 6 additions & 0 deletions internal/framework/controller/predicate/annotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

func TestAnnotationPredicate_Create(t *testing.T) {
t.Parallel()
annotation := "test"

tests := []struct {
Expand Down Expand Up @@ -58,7 +59,9 @@ func TestAnnotationPredicate_Create(t *testing.T) {
p := AnnotationPredicate{Annotation: annotation}

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)
update := p.Create(test.event)
g.Expect(update).To(Equal(test.expUpdate))
Expand All @@ -67,6 +70,7 @@ func TestAnnotationPredicate_Create(t *testing.T) {
}

func TestAnnotationPredicate_Update(t *testing.T) {
t.Parallel()
annotation := "test"

tests := []struct {
Expand Down Expand Up @@ -211,7 +215,9 @@ func TestAnnotationPredicate_Update(t *testing.T) {
p := AnnotationPredicate{Annotation: annotation}

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)
update := p.Update(test.event)
g.Expect(update).To(Equal(test.expUpdate))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

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

p := GatewayClassPredicate{ControllerName: "nginx-ctlr"}
Expand Down
8 changes: 8 additions & 0 deletions internal/framework/controller/predicate/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
)

func TestServicePortsChangedPredicate_Update(t *testing.T) {
t.Parallel()
testcases := []struct {
objectOld client.Object
objectNew client.Object
Expand Down Expand Up @@ -227,7 +228,9 @@ func TestServicePortsChangedPredicate_Update(t *testing.T) {
p := ServicePortsChangedPredicate{}

for _, tc := range testcases {
tc := tc
t.Run(tc.msg, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)
update := p.Update(event.UpdateEvent{
ObjectOld: tc.objectOld,
Expand All @@ -240,6 +243,7 @@ func TestServicePortsChangedPredicate_Update(t *testing.T) {
}

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

p := GatewayServicePredicate{}
Expand All @@ -250,6 +254,7 @@ func TestServicePortsChangedPredicate(t *testing.T) {
}

func TestGatewayServicePredicate_Update(t *testing.T) {
t.Parallel()
testcases := []struct {
objectOld client.Object
objectNew client.Object
Expand Down Expand Up @@ -440,7 +445,9 @@ func TestGatewayServicePredicate_Update(t *testing.T) {
p := GatewayServicePredicate{NSName: types.NamespacedName{Namespace: "nginx-gateway", Name: "nginx"}}

for _, tc := range testcases {
tc := tc
t.Run(tc.msg, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)
update := p.Update(event.UpdateEvent{
ObjectOld: tc.objectOld,
Expand All @@ -453,6 +460,7 @@ func TestGatewayServicePredicate_Update(t *testing.T) {
}

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

p := GatewayServicePredicate{}
Expand Down
3 changes: 3 additions & 0 deletions internal/framework/controller/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
)

func TestRegister(t *testing.T) {
t.Parallel()
type fakes struct {
mgr *controllerfakes.FakeManager
indexer *controllerfakes.FakeFieldIndexer
Expand Down Expand Up @@ -120,7 +121,9 @@ func TestRegister(t *testing.T) {
}

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

newReconciler := func(c controller.ReconcilerConfig) *controller.Reconciler {
Expand Down
3 changes: 3 additions & 0 deletions internal/framework/status/conditions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

func TestConditionsEqual(t *testing.T) {
t.Parallel()
getDefaultConds := func() []v1.Condition {
return []v1.Condition{
{
Expand Down Expand Up @@ -110,7 +111,9 @@ func TestConditionsEqual(t *testing.T) {
}

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)
equal := ConditionsEqual(test.prevConds, test.curConds)
g.Expect(equal).To(Equal(test.expEqual))
Expand Down
1 change: 1 addition & 0 deletions internal/framework/status/status_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

func TestStatus(t *testing.T) {
t.Parallel()
RegisterFailHandler(Fail)
RunSpecs(t, "Status Suite")
}
3 changes: 3 additions & 0 deletions internal/framework/status/updater_retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
)

func TestNewRetryUpdateFunc(t *testing.T) {
t.Parallel()
tests := []struct {
getReturns error
updateReturns error
Expand Down Expand Up @@ -70,7 +71,9 @@ func TestNewRetryUpdateFunc(t *testing.T) {
}

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

fakeStatusUpdater := &statusfakes.FakeK8sUpdater{}
Expand Down

0 comments on commit 2ac3239

Please sign in to comment.