Repository navigation
Deflake TestDynamicSource_FailingSign - #9198
cert-manager-prow[bot] merged 1 commit into
Conversation
Three races made this test flaky; it failed twice in a row on PR cert-manager#9196 CI, once with a panic: - rotate_root and expire_leaf slept for a fixed time before asserting that a new serving certificate had been generated; on a loaded machine regeneration can take longer. Poll with assert.Eventually instead. - The error-expecting cases waited for Start in t.Cleanup, but t.Context is cancelled just before cleanups run, so Start could observe the cancelled context and treat the authority stopping as a clean shutdown, returning nil instead of the expected error. Wait at the end of the test body instead, while the context is still alive. Use assert.ErrorContains so an unexpected nil error fails the test instead of panicking on err.Error(). Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Richard Wall <[email protected]>
There was a problem hiding this comment.
Pull request overview
This pull request deflakes TestDynamicSource_FailingSign by replacing timing-sensitive sleeps and avoiding cleanup-context races.
Changes:
- Uses
assert.Eventuallyfor certificate lifecycle checks. - Waits for expected
Starterrors before cleanup. - Uses
assert.ErrorContainsto avoid nil-error panics.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ThatsMrTalbot 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 |
|
This flake also bites /cherry-pick release-1.21 with claude fable-5 |
|
@wallrj: new pull request created: #9253 DetailsIn response to this:
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-sigs/prow repository. |
After deleting the CA Secret, the test waited for a rotation notification and then did a one-shot Get of the Secret. The notification can be a stale buffered event from the initial CA creation (the watch channel has a buffer of one and the preceding wait returns early when Sign succeeds immediately), so it does not prove the authority has recreated the Secret. On a loaded machine the Get then fails with 'secrets "test-secret" not found', and the empty Secret returned by the failed fake Get makes the follow-up Update fail with 'secrets "" not found'. Poll for the recreated Secret instead, as #9198 did for the TestDynamicSource_FailingSign flakes. Fixes #9242 Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Richard Wall <[email protected]>
Fixes three races that make
TestDynamicSource_FailingSignflaky. It failed twice in a row on the CI for #9196, each time in a different way, once with a panic that took down the other parallel subtests:rotate_rootasserted a new serving certificate 50ms after signalling a root rotation, but regeneration took longer on a loaded machine.certificate_authority_stopped_unexpectedlypanicked in its cleanup. The test waited forStartint.Cleanup, butt.Contextis cancelled just before cleanup functions run, soStart's authority goroutine could observe the cancelled context and treat the stop as a clean shutdown, returning nil instead of the expected error.assert.Errorthen failed and the next line callederr.Error()on the nil error — hence the panic. This window was opened when Bump go 1.24.0 and fix 'usetesting' linter #7783 replaced the explicit cancel-after-Wait handling witht.Context().expire_leaf, has the same fixed-sleep problem asrotate_rootand fails reliably under load (go test -race -count=10).The fix:
assert.Eventuallyinstead of fixed sleeps inrotate_rootandexpire_leaf.Start, wait at the end of the test body — while the test context is still alive — rather than int.Cleanup, and useassert.ErrorContainsso an unexpected nil error fails cleanly instead of panicking.Verified with
go test -race -run TestDynamicSource_FailingSign -count=10 ./pkg/server/tls/(fails on master under this load, passes with this change) andgo test -race -count=3 ./pkg/server/tls/....The fixed sleeps date back to #6784, which added these tests; #6914 already widened the
expire_leafsleep from 100ms to 200ms after CI failures. No behaviour ofDynamicSourceitself is changed./kind cleanup
with claude fable-5