IDEA: Handle panics and make condition result explicit#1
Closed
ubunatic wants to merge 6 commits intoeventually-clean-exitfrom
Closed
IDEA: Handle panics and make condition result explicit#1ubunatic wants to merge 6 commits intoeventually-clean-exitfrom
ubunatic wants to merge 6 commits intoeventually-clean-exitfrom
Conversation
This was referenced Oct 14, 2025
ubunatic
commented
Oct 15, 2025
| } | ||
|
|
||
| func (c *CollectT) failed() bool { | ||
| func (c *CollectT) Failed() bool { |
Owner
Author
There was a problem hiding this comment.
This should be OK to expose, since it is a very std. method and provides utility in tests where you want to reason on the collect status.
If not desired, I can track tests errors in another variable.
See new(assert.CollectT) further below, where I use it.
ubunatic
commented
Oct 15, 2025
| select { | ||
| case <-timer.C: | ||
| return Fail(t, "Condition never satisfied", msgAndArgs...) | ||
| return Fail(t, ResultTimeout, msgAndArgs...) |
ubunatic
commented
Oct 15, 2025
| // We can stop here and now, and mark test as finally failed with | ||
| // the same error message as the timeout case. | ||
| return Fail(t, "Condition never satisfied", msgAndArgs...) | ||
| return FailNow(t, v, msgAndArgs...) |
Owner
Author
There was a problem hiding this comment.
two new messages, since these are two new ways of aborting the eventually
ubunatic
commented
Oct 15, 2025
|
|
||
| func TestFailInsideEventuallyViaCommandLine(t *testing.T) { | ||
| t.Setenv("TestFailInsideEventually", "1") | ||
| cmd := exec.Command("go", "test", "-v", "-race", "-count=1", "-run", "^TestFailInsideEventually$") |
Owner
Author
There was a problem hiding this comment.
Another clean alternative would be to store the log output from the always failing test as test fixure. And only analyze the fixure here.
The fixure can be create are part of the code gen.
I am not sure we can easily extend MockT to reproduce this.
2774c83 to
80bd5f0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Catch all possible results, incl. panics, that can happen to a condition inside the
Eventuallyimplementation and use a corresponding error message.This Demo PR in my contrib repo is an alternative implementation to stretchr#1809.
Changes
t.Errorfgo testtest to better analyze the failed test logs for thetesting.TlogMotivation
Related issues
Eventuallyon failed condition stretchr/testify#1809Eventuallyhangs on failed/abortedconditionstretchr/testify#1810