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

prevent predicatesOrdering from escaping from UT #77576

Merged
merged 1 commit into from
May 9, 2019

Conversation

Huang-Wei
Copy link
Member

What type of PR is this?

/kind bug
/kind failing-test
/sig scheduling
/priority important-soon

What this PR does / why we need it:

generic_scheduler_test.go modifies "predicatesOrdering" in UT without setting it back. This causes modified "predicatesOrdering" to be effective in the entire unit test lifecycle, hence could lead to flaky tests and unexpected behavior. For example, it fails when running TestPreempt only:

$ go test k8s.io/kubernetes/pkg/scheduler/core -run "^TestPreempt$"
-- FAIL: TestPreempt (0.00s)
    --- FAIL: TestPreempt/basic_preemption_logic (0.00s)
        generic_scheduler_test.go:1467: ===== Running test TestPreempt/basic_preemption_logic
        generic_scheduler_test.go:1512: expected node: machine1, got: machine2
        generic_scheduler_test.go:1518: expected 2 pods, got 0.
    --- FAIL: TestPreempt/One_node_doesn't_need_any_preemption (0.00s)
        generic_scheduler_test.go:1467: ===== Running test TestPreempt/One_node_doesn't_need_any_preemption
        generic_scheduler_test.go:1512: expected node: machine3, got: machine1
    --- FAIL: TestPreempt/Scheduler_extenders_allow_only_machine1,_otherwise_machine3_would_have_been_chosen (0.00s)
        generic_scheduler_test.go:1467: ===== Running test TestPreempt/Scheduler_extenders_allow_only_machine1,_otherwise_machine3_would_have_been_chosen
        generic_scheduler_test.go:1518: expected 2 pods, got 0.
    --- FAIL: TestPreempt/One_scheduler_extender_allows_only_machine1,_the_other_returns_error_but_ignorable._Only_machine1_would_be_chosen (0.00s)
        generic_scheduler_test.go:1467: ===== Running test TestPreempt/One_scheduler_extender_allows_only_machine1,_the_other_returns_error_but_ignorable._Only_machine1_would_be_chosen
        generic_scheduler_test.go:1518: expected 2 pods, got 0.
    --- FAIL: TestPreempt/One_scheduler_extender_allows_only_machine1,_but_it_is_not_interested_in_given_pod,_otherwise_machine1_would_have_been_chosen (0.00s)
        generic_scheduler_test.go:1467: ===== Running test TestPreempt/One_scheduler_extender_allows_only_machine1,_but_it_is_not_interested_in_given_pod,_otherwise_machine1_would_have_been_chosen
        generic_scheduler_test.go:1512: expected node: machine3, got: machine2
FAIL
FAIL    k8s.io/kubernetes/pkg/scheduler/core    0.011s

Special notes for your reviewer:

If appropriate, we can remove function SetPredicatesOrdering() - there is no usage inside k8s codebase.

Does this PR introduce a user-facing change?:

NONE

/assign @k82cn @bsalamat

@k8s-ci-robot k8s-ci-robot added the release-note-none Denotes a PR that doesn't merit a release note. label May 8, 2019
@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. kind/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 8, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Huang-Wei

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 May 8, 2019
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, @Huang-Wei

@@ -217,7 +217,7 @@ func TestSelectHost(t *testing.T) {
}

func TestGenericScheduler(t *testing.T) {
algorithmpredicates.SetPredicatesOrdering(order)
defer algorithmpredicates.SetPredicatesOrderingDuringTest(order)()
Copy link
Member

Choose a reason for hiding this comment

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

nit: this is clever, but a bit unreadable. One might think that the whole line is defered and executed after the function returns. Optionally, you can store and defer the returned function, but it is up to you.

Copy link
Member Author

Choose a reason for hiding this comment

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

Credit goes to @liggitt :)

defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.XYZ, true)()

@@ -174,6 +174,9 @@ func Ordering() []string {
}

// SetPredicatesOrdering sets the ordering of predicates.
// CAVEAT: be cautious with the usage.
// It can cause predicatesOrdering to be modified permanately.
// If your intention is writing a test, the correct way is utils.go#SetPredicatesOrderingDuringTest().
func SetPredicatesOrdering(names []string) {
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this 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. PTAL.

- sets `predicatesOrdering` back to original value in UT
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

Thanks, @Huang-Wei

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 9, 2019
@k8s-ci-robot k8s-ci-robot merged commit 3ab338d into kubernetes:master May 9, 2019
@Huang-Wei Huang-Wei deleted the sched-ut-escape branch May 10, 2019 05:13
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/bug Categorizes issue or PR as related to a bug. kind/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note-none Denotes a PR that doesn't merit a release note. 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