Skip to content

Stop the DCR recheck tests racing their loop - #7172

Merged
jhrozek merged 1 commit into
mainfrom
deflake-dcr-recheck-tests
Nov 25, 2026
Merged

jhrozek merged 1 commit into
mainfrom
deflake-dcr-recheck-tests

Conversation

@jhrozek

@jhrozek jhrozek commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Summary

TestEmbeddedAuthServer_DCRRecheckFollowsMovedTokenEndpoint failed once in CI with a data race and expected: ["iat-1","iat-2"] actual: ["iat-1","iat-1"]. The test builds an embedded auth server with RegistrationProbeInterval: "1m", which also starts the background re-check loop. The loop's first tick fires at a random point in the first minute, and the test calls tick by hand as well. When the loop's tick lands during the test, the two ticks overlap: both touch current in tick without synchronisation, and the background tick can use up the initial access token the test wanted to present.

  • Stop the re-check loop right after the server is built in the two tests that drive re-checks by hand (TestEmbeddedAuthServer_DCRRecheckRecoversWithoutRestart and TestEmbeddedAuthServer_DCRRecheckFollowsMovedTokenEndpoint), so the manual ticks are the only ones.
  • No assertions change.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe): test-only deflake

Test plan

  • Unit tests (task test): ran its go test -race flags scoped to ./pkg/authserver/runner/ (the re-check tests 20 times, the whole package twice), not the whole repo. CI runs the rest.
  • Linting (task lint-fix): ran golangci-lint run ./pkg/authserver/runner/... on the package only, 0 issues; gofmt and go vet clean.
  • Manual testing: the config validation requires at least one minute, so to force the overlap I temporarily lowered MinRegistrationProbeInterval and set the tests' interval to 5ms. Before the fix, 20 runs with -race gave 38 failing test runs, including the same ["iat-1","iat-1"] assertion and a data race at dcr_recheck.go:166. After the fix, 60 runs with the same forcing were clean. The forcing edit is not part of this change.

Does this introduce a user-facing change?

No

Special notes for reviewers

  • Production code only calls tick from run(), so there is no race in the product, only in how the tests used the loop. That is why the fix is test-only and adds no lock.
  • With the 1m interval the first tick is uniform in [0, 1m), so a run of a few hundred milliseconds hits it with a probability well under 1 percent. That matches seeing it rarely in CI, and is why a longer interval is not an option: 1m is the minimum the config accepts, and a probabilistic fix would only make the flake rarer.
  • stopDCRRechecks is the function the server already uses in Close. It cancels the loop and waits for in-flight ticks, and calling it again from Close is harmless.
  • The other tests in the file call tick on a dcrRecheck they build themselves, with no loop running, so they are not affected.

Two tests build an embedded auth server with a
RegistrationProbeInterval, which also starts the background re-check
loop, and then call tick by hand to drive the re-check. The loop's
first tick fires at a random moment in the first minute, so it
sometimes ran during the test. The two ticks then touched the
re-check's current resolution at the same time (a data race), and the
background tick could spend the initial access token the test meant to
use, giving ["iat-1","iat-1"] instead of ["iat-1","iat-2"].

Stop the loop right after the server is built, so the manual ticks are
the only ones. Production only ticks from the loop, so no production
change is needed.

Co-authored-by: Mecatl <[email protected]>
@github-actions github-actions Bot added the size/XS Extra small PR: < 100 lines changed label Nov 17, 2026

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Draft review: no significant findings; this looks right to approve once it is marked ready.

Design: The flake comes from NewEmbeddedAuthServerWithStorage starting the DCR re-check goroutines immediately, while these two tests also drive re-checks by hand with tick(), so a background tick could race on r.current. Stopping the loop in the tests is the right place for the fix: production should keep the loop running, and stopDCRRechecks is synchronous (cancel + wg.Wait) and idempotent, so the later Close call is safe. These are the only two tests that build a full EmbeddedAuthServer with RegistrationProbeInterval and call tick() manually, and the loop itself stays covered by TestStartDCRRechecks_StopsLoops. No production code or upgrade behaviour changes.

🤖 Reviewed with Claude Code

@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.41%. Comparing base (09e8d21) to head (55c8aca).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7172      +/-   ##
==========================================
+ Coverage   81.39%   81.41%   +0.02%     
==========================================
  Files         890      890              
  Lines       90704    90736      +32     
==========================================
+ Hits        73831    73877      +46     
+ Misses      16868    16854      -14     
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jhrozek
jhrozek marked this pull request as ready for review November 17, 2026 14:35
@jhrozek
jhrozek requested a review from ChrisJBurns as a code owner November 17, 2026 14:35
@jhrozek
jhrozek merged commit 62b6e1c into main Nov 25, 2026
48 checks passed
@jhrozek
jhrozek deleted the deflake-dcr-recheck-tests branch November 25, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Extra small PR: < 100 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants