Repository navigation
[release-1.21] Fix flaky goroutine-leak test in pkg/scheduler - #9261
Merged
cert-manager-prow[bot] merged 2 commits intoSep 3, 2026
Conversation
Test_afterFunc/stop_works starts 10000 afterFunc goroutines, cancels them all, then sleeps a fixed 100ms before comparing runtime.NumGoroutine() against the baseline taken at the start. Those goroutines exit asynchronously, so on a loaded machine 100ms is not nearly long enough for 10000 of them to be scheduled and exit, and the test fails despite there being no leak. Reproducing it showed a second, independent problem. The assertion used assert.InDelta, which fails in both directions, but this is a leak check where only an increase matters. Tests sharing the binary run concurrently, so the baseline can include goroutines that have since exited, leaving fewer at the end than there were at the start. - Poll for the count to come back down, up to a 30s deadline, rather than sleeping a fixed amount. A real leak never recovers, so it still fails once the deadline passes. - Assert an upper bound with assert.LessOrEqual instead of a two-sided delta. Verified by pinning the prebuilt test binary to a single saturated core: 2 of 8 runs failed before the change, exercising both directions (once 1494 goroutines above the baseline, once 1494 below it), and 15 of 15 passed after. Also checked the test still catches a real leak rather than merely having been made unfailable, by temporarily replacing the "case <-cancelCh: return" in afterFunc with a block that never returns. It fails as intended, with "10000 is not less than or equal to 100". Signed-off-by: Richard Wall <[email protected]>
Review of the previous commit found two problems: - The comment justifying the one-sided assertion claimed that tests sharing the binary run concurrently, but no test in this package calls t.Parallel() and Test_afterFunc runs first, so nothing runs concurrently with it. The below-baseline counts come from `go test -count=N` reruns, where one run's baseline includes still-draining goroutines from the previous run. - The hand-rolled deadline/sleep loop re-implemented assert.Eventually, which is already imported here and is the established pattern for poll-until-deadline assertions elsewhere in this repository. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Richard Wall <[email protected]>
Member
|
/kind flake |
Member
|
/lgtm |
Contributor
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: wallrj The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
cert-manager-prow
Bot
merged commit Sep 3, 2026
b6af109
into
cert-manager:release-1.21
6 checks passed
This was referenced Sep 3, 2026
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.
This is an automated cherry-pick of #9217
Fixes #9250
/assign wallrj