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

Speed up pkg/controller/volume/scheduling unit tests #98912

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 16 additions & 2 deletions pkg/controller/volume/scheduling/scheduler_binder_test.go
Expand Up @@ -785,7 +785,7 @@ func makePodWithoutPVC() *v1.Pod {
}

func makeBinding(pvc *v1.PersistentVolumeClaim, pv *v1.PersistentVolume) *BindingInfo {
return &BindingInfo{pvc: pvc, pv: pv}
return &BindingInfo{pvc: pvc.DeepCopy(), pv: pv.DeepCopy()}
}

func addProvisionAnn(pvc *v1.PersistentVolumeClaim) *v1.PersistentVolumeClaim {
Expand Down Expand Up @@ -846,6 +846,8 @@ func findPodVolumes(binder SchedulerVolumeBinder, pod *v1.Pod, node *v1.Node) (*
}

func TestFindPodVolumesWithoutProvisioning(t *testing.T) {
t.Parallel()

type scenarioType struct {
// Inputs
pvs []*v1.PersistentVolume
Expand Down Expand Up @@ -1016,6 +1018,8 @@ func TestFindPodVolumesWithoutProvisioning(t *testing.T) {
}

func TestFindPodVolumesWithProvisioning(t *testing.T) {
t.Parallel()

type scenarioType struct {
// Inputs
pvs []*v1.PersistentVolume
Expand Down Expand Up @@ -1527,6 +1531,8 @@ func TestBindAPIUpdate(t *testing.T) {
}

func TestCheckBindings(t *testing.T) {
t.Parallel()

type scenarioType struct {
// Inputs
initPVs []*v1.PersistentVolume
Expand Down Expand Up @@ -1724,6 +1730,8 @@ func TestCheckBindings(t *testing.T) {
}

func TestCheckBindingsWithCSIMigration(t *testing.T) {
t.Parallel()

type scenarioType struct {
// Inputs
initPVs []*v1.PersistentVolume
Expand Down Expand Up @@ -1844,6 +1852,8 @@ func TestCheckBindingsWithCSIMigration(t *testing.T) {
}

func TestBindPodVolumes(t *testing.T) {
t.Parallel()

type scenarioType struct {
// Inputs
bindingsNil bool // Pass in nil bindings slice
Expand Down Expand Up @@ -2053,7 +2063,11 @@ func TestBindPodVolumes(t *testing.T) {
}

for name, scenario := range scenarios {
t.Run(name, func(t *testing.T) { run(t, scenario) })
scenario := scenario
t.Run(name, func(t *testing.T) {
t.Parallel()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need t.Parallel() here and at the top of the Test function? I see the other test cases don't have the call here, and most examples I see have the parallel call inside the t.Run()

Copy link
Member Author

@wzshiming wzshiming Mar 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this test function takes a minute here, add t.Parallel() to t.Run() to make all cases in the parallel.

Copy link
Member Author

@wzshiming wzshiming Mar 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found that scenario is a shared state.

for name, scenario := range scenarios {
      scenario := scenario
      t.Run(name, func(t *testing.T) {
	      t.Parallel()
	      run(t, scenario)
      })
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Updated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great find! Thanks!

run(t, scenario)
})
}
}

Expand Down