fix(assert): prevent panic on nil condition in Eventually and Never - #1980
Closed
AdamMagued wants to merge 1 commit into
Closed
AdamMagued wants to merge 1 commit into
AdamMagued wants to merge 1 commit into
Conversation
Validate that condition is non-nil and tick is greater than 0 in Eventually, EventuallyWithT, and Never. Previously, a nil condition panicked on a newly spawned goroutine, causing the entire test binary to crash unrecoverably without reporting assertion failure to TestingT. Passing a non-positive tick also panicked in time.NewTicker. Both cases now cleanly fail the assertion via Fail and return false. Fixes stretchr#1970
Author
|
Closing in favor of issue author's PR #1971 to keep the review queue clean. |
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.
Validate that condition != nil and tick > 0 at the start of Eventually, EventuallyWithT, and Never before creating timers or spawning worker goroutines.
Previously, passing a nil condition to Eventually, EventuallyWithT, or Never caused a panic inside a newly spawned goroutine when executing condition(). Because the panic occurred on a separate goroutine, it could not be recovered by the calling test function and caused the entire test binary to abort without reporting an assertion failure to TestingT. Similarly, passing a non-positive tick caused time.NewTicker to panic.
With this change:
Fixes #1970