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
Speed up pkg/controller/volume/scheduling unit tests #98912
Conversation
@wzshiming: This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
/retest |
1 similar comment
/retest |
@@ -2002,7 +2012,7 @@ func TestBindPodVolumes(t *testing.T) { | |||
claimsToProvision := []*v1.PersistentVolumeClaim{} | |||
if !scenario.bindingsNil { | |||
if scenario.binding != nil { | |||
bindings = []*BindingInfo{scenario.binding} | |||
bindings = []*BindingInfo{makeBinding(scenario.binding.pvc, scenario.binding.pv)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you call makeBinding
twice? In scenario definitions and here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If don't add this, it will fail when run stress.
5s: 0 runs so far, 0 failures
10s: 0 runs so far, 0 failures
15s: 0 runs so far, 0 failures
20s: 0 runs so far, 0 failures
/var/folders/6v/7stmg2756wlfk9c_qnv1hnbm0000gn/T/go-stress-20210227T142520-109974642
==================
WARNING: DATA RACE
Read at 0x00c000424cc8 by goroutine 223:
k8s.io/kubernetes/pkg/controller/volume/scheduling.(*testEnv).assumeVolumes()
/Users/zsm/go/src/k8s.io/kubernetes/pkg/controller/volume/scheduling/scheduler_binder_test.go:401 +0x11a
k8s.io/kubernetes/pkg/controller/volume/scheduling.TestBindPodVolumes.func6()
/Users/zsm/go/src/k8s.io/kubernetes/pkg/controller/volume/scheduling/scheduler_binder_test.go:2023 +0xbaa
k8s.io/kubernetes/pkg/controller/volume/scheduling.TestBindPodVolumes.func7()
/Users/zsm/go/src/k8s.io/kubernetes/pkg/controller/volume/scheduling/scheduler_binder_test.go:2068 +0x101
testing.tRunner()
/usr/local/Cellar/go/1.15.6/libexec/src/testing/testing.go:1123 +0x202
Previous write at 0x00c000424cc8 by goroutine 81:
k8s.io/kubernetes/pkg/controller/volume/scheduling.(*volumeBinder).bindAPIUpdate()
/Users/zsm/go/src/k8s.io/kubernetes/pkg/controller/volume/scheduling/scheduler_binder.go:507 +0x8c5
k8s.io/kubernetes/pkg/controller/volume/scheduling.(*volumeBinder).BindPodVolumes()
/Users/zsm/go/src/k8s.io/kubernetes/pkg/controller/volume/scheduling/scheduler_binder.go:442 +0x376
k8s.io/kubernetes/pkg/controller/volume/scheduling.TestBindPodVolumes.func6()
/Users/zsm/go/src/k8s.io/kubernetes/pkg/controller/volume/scheduling/scheduler_binder_test.go:2054 +0x301
k8s.io/kubernetes/pkg/controller/volume/scheduling.TestBindPodVolumes.func7()
/Users/zsm/go/src/k8s.io/kubernetes/pkg/controller/volume/scheduling/scheduler_binder_test.go:2068 +0x101
testing.tRunner()
/usr/local/Cellar/go/1.15.6/libexec/src/testing/testing.go:1123 +0x202
Goroutine 223 (running) created at:
testing.(*T).Run()
/usr/local/Cellar/go/1.15.6/libexec/src/testing/testing.go:1168 +0x5bb
k8s.io/kubernetes/pkg/controller/volume/scheduling.TestBindPodVolumes()
/Users/zsm/go/src/k8s.io/kubernetes/pkg/controller/volume/scheduling/scheduler_binder_test.go:2066 +0x19d3
testing.tRunner()
/usr/local/Cellar/go/1.15.6/libexe
…
25s: 3 runs so far, 1 failures (33.33%)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scenario.binding
should be local to each test case. If not, that seems to indicate there is still some shared state somewhere.
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: msau42, wzshiming The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/hold |
@@ -2002,7 +2012,7 @@ func TestBindPodVolumes(t *testing.T) { | |||
claimsToProvision := []*v1.PersistentVolumeClaim{} | |||
if !scenario.bindingsNil { | |||
if scenario.binding != nil { | |||
bindings = []*BindingInfo{scenario.binding} | |||
bindings = []*BindingInfo{makeBinding(scenario.binding.pvc, scenario.binding.pv)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scenario.binding
should be local to each test case. If not, that seems to indicate there is still some shared state somewhere.
@@ -2053,7 +2063,10 @@ func TestBindPodVolumes(t *testing.T) { | |||
} | |||
|
|||
for name, scenario := range scenarios { | |||
t.Run(name, func(t *testing.T) { run(t, scenario) }) | |||
t.Run(name, func(t *testing.T) { | |||
t.Parallel() |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
})
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great find! Thanks!
5b2281d
to
67e4ba0
Compare
/lgtm |
Thank you!! |
What type of PR is this?
/kind cleanup
/kind flake
What this PR does / why we need it:
109s -> 24s
Which issue(s) this PR fixes:
xref #98486
Special notes for your reviewer:
Does this PR introduce a user-facing change?:
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: