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 the "Expect(err).NotTo(HaveOccurred())" and "ExpectNoError(err)" anti-pattern in e2e tests #109600
Comments
@pohly: 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. |
One thing that we could do is add an empty string as explanation with a TODO comment to all current calls that don't have one and then make the explanation parameter(s) required in kubernetes/test/e2e/framework/expect.go Lines 38 to 41 in f173d01
Code without an explanation then would look like this:
|
The "TODO" could be removed in places where the error is known to be informative enough. The problem is that this can only be determined by examining the code. It also might not be obvious. I'm leaning to always requiring a non-empty string, everything else seems rather fragile. |
+1 for requiring a non-empty string. I suggest we update all the functions in kubernetes/test/e2e/framework/expect.go to make adding some context non-optional, for example: // ExpectNoError checks if "err" is set, and if so, fails assertion while logging the error.
// context should describe where the error came from, such as the intent of the call that produced the error.
func ExpectNoError(err error, contextMsg string, explain ...interface{}) {
if contextMsg == "" { /* fail */ }
explain = append([]interface{}{contextMsg}, explain...)
ExpectNoErrorWithOffset(1, err, explain...)
} As a first pass, callers could just be updated to set the contextMsg to |
Hey guys, can I try to fix this one?
and for those calls without contextMsg, I can temporarily replace it with an empty string,like so it can print the message about this issue,and it doesn't affect compilation |
I would just continue to call it How does this sound?
It's worth calling out that we loose some functionality when doing this: previously, I agree that just passing "TODO" sounds like a good idea. Do we want to do this in one PR or in multiple? If we do it in one, we pretty much need a root approver, otherwise it will be blocked until all the various tests owners add their approval. It could easily get stuck in rebase hell. If we split it up along ownership boundaries, we still need lots of approvals, but might have to rebase less. I'd prefer a single PR that goes in early in the 1.25 cycle, if we can get that through. @kidddddddddddddddddddddd: you are welcome to work on this, but let's first clarify exactly what we want and how to do it. |
I also prefer a single PR. |
Such a single PR must be very simple, otherwise we get bogged down in discussions around what individual strings should be. Therefore |
Sounds good to me,I'll make a simple PR in a day or two. |
/assign |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
/lifecycle frozen |
We are not done with this and it is still a problem. The number one error on https://storage.googleapis.com/k8s-triage/index.html right now is:
kubernetes/test/e2e/framework/framework.go Lines 247 to 248 in cbd16cf
|
So I suggested on #109728 that this is not an Changing the API would also provide an opportunity to add a way to say "if you time out, return the last error returned from the Maybe they could all take an input struct like |
I agree that this must be the first step. I wrote down some thoughts about what polling should support here: I implemented what I envision to meet these requirements here: But I still think that adding additional information in
Even if the improved error now includes the pod name, test failures become better when explaining what the pod is for:
I'm coming to the conclusion that there's no technical solution for this: test authors and reviewers will have to consider manually whether it should be called with an additional explanation. |
What would you like to be added?
This was previously tracked in #34059 (created in 2016, closed in 2020 after several tests were enhanced).
I'm starting to wonder whether the problem is getting worse again because we still don't catch new tests that use this anti-pattern (for example, #107763).
Is it time to start another spring clean which removes occurrences of this anti-pattern? Or perhaps add some mechanism that prevents it in new code?
/sig testing
/area e2e-test-framework
Why is this needed?
I'm getting tired of seeing failures where the only output is
This is the result of
or more recently
An explanation string would help, but even better solutions would be possible (#106575).
The text was updated successfully, but these errors were encountered: