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

Refactor and clean up e2e framework utils, this patch handles test/e2e/framework/psp_util.go file #77534

Merged
merged 1 commit into from Aug 1, 2019

Conversation

WanLinghao
Copy link
Contributor

/kind cleanup

What this PR does / why we need it:
Refactor and clean up e2e framework utils, this patch handles test/e2e/framework/perf_util.go file
ref:#76206

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels May 7, 2019
@k8s-ci-robot k8s-ci-robot added area/e2e-test-framework Issues or PRs related to refactoring the kubernetes e2e test framework area/test sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels May 7, 2019
@WanLinghao
Copy link
Contributor Author

/hold
wait for #77536 merged

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 7, 2019
@fejta
Copy link
Contributor

fejta commented May 9, 2019

Can you create OWNERS files for the psp dir please?
/assign @timothysc

Copy link
Member

@timothysc timothysc left a comment

Choose a reason for hiding this comment

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

/approve

but you need add the generated files and OWNERs files.

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels May 13, 2019
@andrewsykim
Copy link
Member

Overall lgtm, can you rebase please?

@alejandrox1
Copy link
Contributor

Hi @WanLinghao any updates on this?
/assign

@WanLinghao
Copy link
Contributor Author

@alejandrox1 Sorry for the delay, I have checked this, it is not ready to merge. We must take care of ExpectNoError functions before continue. Or it could cause package import cycle.

@alejandrox1
Copy link
Contributor

alejandrox1 commented Jul 23, 2019

@alejandrox1 Sorry for the delay, I have checked this, it is not ready to merge. We must take care of ExpectNoError functions before continue. Or it could cause package import cycle.

Sorry for the delay as well, there is actually been some debate about how to handle framework.ExpectNoError().

To get in the same page, framework.ExpectNoError() wraps a call to

framework.ExpectNoErrorWithOffset(1, err, explain...)

framework.ExpectNoErrorWithOffset() itself being a wrapper for

gomega.ExpectWithOffset(1, err).NotTo(gomega.HaveOccurred(), explain...)}

The first argument to gomega.ExpectWithOffset() represents the offset in the call stack.

For example, if you have a test, and you perform certain actions in your test through helper functions and an assertion in one of these helper function fails the line numbers provided by Gomega will point you to the line in the helper function that failed instead of showing you the line in your test that failed.

framework.ExpectNoError() will, by default, call gomega.ExpectWithOffset() with an offset equal to 1, which means that a failed assertion will be logged for the caller of the method where gomega.ExpectWithOffset() is used.

framework.ExpectNoError() was then implemented with the aim of using it within helper functions in e2e tests.
This way, if an assertion failed we would obtain information about the specific step within the e2e test that failed and would avoid having to backtrace what part of what test made a call to the given function.

With that in mind, in order to refactor code from the framework into its own package within the framework (i.e., e2e/framework/psp), we need to replace calls to framework.ExpectNoError() with either gomega.Expect() or gomega.ExectWithOffset().
The simplest way would be then to replace a framework.ExpectNoError() with the following:

if err != nil {
	e2elog.Logf("Unexpected error occurred: %v", err)
}
gomega.ExpectWithOffset(1+offset, err).NotTo(gomega.HaveOccurred(), explain...)

Which replaces the call to framework.ExpectNoError() with the code that it ends up calling.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jul 26, 2019
@WanLinghao
Copy link
Contributor Author

@alejandrox1 Hi, this patch is ready to review

Copy link
Contributor

@fejta fejta 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
/hold
Do we want an owners file for framework/psp?

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

fejta commented Jul 26, 2019

/retest

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fejta, timothysc, WanLinghao

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 removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 27, 2019
@WanLinghao
Copy link
Contributor Author

/test pull-kubernetes-e2e-gce-device-plugin-gpu

@WanLinghao
Copy link
Contributor Author

@fejta Hi, I updated the patch to fix a golint error.

if err != nil {
e2elog.Logf("Unexpected error occurred: %v", err)
}
gomega.ExpectWithOffset(2, err).NotTo(gomega.HaveOccurred(), explain...)
Copy link
Contributor

Choose a reason for hiding this comment

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

the ExpectNoError from the framework calls gomega.ExpectWithOffset(1, err) not gomega.ExpectWithOffset(2, err), correct? If so, we should change this.
This patch changes the current behavior. Which is not wrong but we should add it in a separate PR and only focus on refactoring for this on. This way we can revert if something starts failing in CI.

/lgtm cancel

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alejandrox1 Do you mean we should change gomega.ExpectWithOffset(2, err).NotTo(gomega.HaveOccurred(), explain...) to gomega.ExpectWithOffset(1, err).NotTo(gomega.HaveOccurred(), explain...)? But I believe the original definition should be gomega.ExpectWithOffset(2, err).NotTo(gomega.HaveOccurred(), explain...)

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, you are completely right!
Given https://github.com/kubernetes/kubernetes/blob/master/test/e2e/framework/util.go#L1321
a framework.NoExpectError is equivalent to gomega.ExpectWithOffset(2, err).NotTo(gomega.HaveOccurred(), explain...).

/lgtm
/hold cancel

@alejandrox1
Copy link
Contributor

Do we want an owners file for framework/psp?

I believe the consensus thus far has to keep all e2e framework subpkgs under the same ownership.
/priority backlog

@k8s-ci-robot k8s-ci-robot added priority/backlog Higher priority than priority/awaiting-more-evidence. lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Jul 29, 2019
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@k8s-ci-robot k8s-ci-robot merged commit 9fdda3f into kubernetes:master Aug 1, 2019
@k8s-ci-robot k8s-ci-robot added this to the v1.16 milestone Aug 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. area/e2e-test-framework Issues or PRs related to refactoring the kubernetes e2e test framework area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/backlog Higher priority than priority/awaiting-more-evidence. release-note-none Denotes a PR that doesn't merit a release note. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants