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

fix the flake in scheduling_queue_test #74611

Merged

Conversation

denkensk
Copy link
Member

@denkensk denkensk commented Feb 26, 2019

What type of PR is this?
/kind failing-test
/kind flake
/sig scheduling

What this PR does / why we need it:
seeing a flake in scheduling unit tests - https://storage.googleapis.com/k8s-gubernator/triage/index.html?pr=1&text=Unable%20to%20find%20backoff%20value

Which issue(s) this PR fixes:
Fixes #73700 (comment)

fix the flake in scheduling_queue_test.go

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Feb 26, 2019
@k8s-ci-robot k8s-ci-robot added sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. kind/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. kind/flake Categorizes issue or PR as related to a flaky test. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Feb 26, 2019
@denkensk denkensk force-pushed the fix-unable-find-backoff-value branch from 8e40352 to a7866e4 Compare February 26, 2019 19:01
@denkensk
Copy link
Member Author

/assign @bsalamat

flushBackoffQ := func() operation {
return func() {
// wait for pod to complete backoff.
time.Sleep(time.Second)
Copy link
Member

Choose a reason for hiding this comment

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

Can you collaborate why this is needed? And it seems to be able to transfer to a more grace solution like channel or wait?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. Thanks. I transfer to a more grace solution. Done

Copy link
Member

@bsalamat bsalamat left a comment

Choose a reason for hiding this comment

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

Thanks, @denkensk for your quick fix. I think we can improve the test further to avoid similar issues in the future and to have better control over test cases. Please see my comment.

flushBackoffQ := func() operation {
return func() {
// wait for pod to complete backoff.
time.Sleep(time.Second)
Copy link
Member

Choose a reason for hiding this comment

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

A better approach is to use NewPriorityQueueWithClock instead of NewPriorityQueue at line 1122 and pass a FakeClock (k8s.io/apimachinery/pkg/util/clock) to it. You can then control the time with the fake clock, for example by calling its Step function.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done thank you for your help.

@denkensk denkensk force-pushed the fix-unable-find-backoff-value branch 2 times, most recently from 1fbe499 to 1a92402 Compare February 26, 2019 19:39
@denkensk
Copy link
Member Author

Test is ok. PTAL @bsalamat thank you.

Copy link
Member

@bsalamat bsalamat left a comment

Choose a reason for hiding this comment

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

Thanks, @denkensk! Just a couple of minor comments.

},
expected: []*podInfo{pInfo1, pInfo2},
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
queue = NewPriorityQueue(nil)
queue = NewPriorityQueueWithClock(nil, clock.NewFakeClock(time.Now()))
Copy link
Member

Choose a reason for hiding this comment

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

time.Now() changes every time you read it. In order to have a robust test, please read it once in the beginning of the function and use that time here and for initializing pInfo1 and pInfo2 in lines 1026 and 1030.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, Thanks for your advice. Done

flushBackoffQ := func() operation {
return func() {
queue.clock.(*clock.FakeClock).Step(queue.podBackoff.MaxDuration())
Copy link
Member

Choose a reason for hiding this comment

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

It is better to Step 2 seconds here instead of MaxDuration. That would be a more precise test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done thanks

@denkensk denkensk force-pushed the fix-unable-find-backoff-value branch from 1a92402 to 471679f Compare February 27, 2019 23:23
Copy link
Member

@bsalamat bsalamat left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

Thanks, @denkensk!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 28, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bsalamat, denkensk

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 28, 2019
@k8s-ci-robot k8s-ci-robot merged commit f6d05d6 into kubernetes:master Mar 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. kind/flake Categorizes issue or PR as related to a flaky test. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants