Skip to content

Deflake TestDynamicSource_FailingSign - #9198

Merged
cert-manager-prow[bot] merged 1 commit into
cert-manager:masterfrom
wallrj:fix-dynamic-source-rotate-flake
Aug 26, 2026
Merged

cert-manager-prow[bot] merged 1 commit into
cert-manager:masterfrom
wallrj:fix-dynamic-source-rotate-flake

Conversation

@wallrj

@wallrj wallrj commented Aug 25, 2026 •

Copy link
Copy Markdown
Member

Fixes three races that make TestDynamicSource_FailingSign flaky. 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:

  • failure 1: rotate_root asserted a new serving certificate 50ms after signalling a root rotation, but regeneration took longer on a loaded machine.
  • failure 2: certificate_authority_stopped_unexpectedly panicked in its cleanup. The test waited for Start in t.Cleanup, but t.Context is cancelled just before cleanup functions run, so Start's authority goroutine could observe the cancelled context and treat the stop as a clean shutdown, returning nil instead of the expected error. assert.Error then failed and the next line called err.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 with t.Context().
  • A third case, expire_leaf, has the same fixed-sleep problem as rotate_root and fails reliably under load (go test -race -count=10).

The fix:

  • Poll with assert.Eventually instead of fixed sleeps in rotate_root and expire_leaf.
  • For the cases that expect an error from Start, wait at the end of the test body — while the test context is still alive — rather than in t.Cleanup, and use assert.ErrorContains so 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) and go test -race -count=3 ./pkg/server/tls/....

The fixed sleeps date back to #6784, which added these tests; #6914 already widened the expire_leaf sleep from 100ms to 200ms after CI failures. No behaviour of DynamicSource itself is changed.

/kind cleanup

NONE

with claude fable-5

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]>
@cert-manager-prow cert-manager-prow Bot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. labels Aug 25, 2026
@cert-manager-prow cert-manager-prow Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 25, 2026
@wallrj
wallrj requested a lite review from Copilot August 25, 2026 06:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request deflakes TestDynamicSource_FailingSign by replacing timing-sensitive sleeps and avoiding cleanup-context races.

Changes:

  • Uses assert.Eventually for certificate lifecycle checks.
  • Waits for expected Start errors before cleanup.
  • Uses assert.ErrorContains to avoid nil-error panics.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@wallrj
wallrj requested a review from ThatsMrTalbot August 26, 2026 15:14
@ThatsMrTalbot

Copy link
Copy Markdown
Contributor

/lgtm
/approve

@cert-manager-prow cert-manager-prow Bot added the lgtm Indicates that a PR is ready to be merged. label Aug 26, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@cert-manager-prow cert-manager-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 26, 2026
@cert-manager-prow
cert-manager-prow Bot merged commit 9d92868 into cert-manager:master Aug 26, 2026
6 checks passed
@wallrj

wallrj commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

This flake also bites release-1.21 CI, where this fix has not landed: TestDynamicSource_FailingSign/certificate_authority_stopped_unexpectedly failed pull-cert-manager-release-1.21-make-test on #9238 with An error is expected but got nil followed by a nil-pointer panic. Backporting this test-only fix to keep the release branch CI healthy, per the v1.21.1 prior art of backporting the e2e-only fix #9058.

/cherry-pick release-1.21

with claude fable-5

@cert-manager-bot

Copy link
Copy Markdown
Contributor

@wallrj: new pull request created: #9253

Details

In response to this:

This flake also bites release-1.21 CI, where this fix has not landed: TestDynamicSource_FailingSign/certificate_authority_stopped_unexpectedly failed pull-cert-manager-release-1.21-make-test on #9238 with An error is expected but got nil followed by a nil-pointer panic. Backporting this test-only fix to keep the release branch CI healthy, per the v1.21.1 prior art of backporting the e2e-only fix #9058.

/cherry-pick release-1.21

with claude fable-5

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.

cert-manager-prow Bot pushed a commit that referenced this pull request Nov 1, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants