Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4497 +/- ##
==========================================
- Coverage 69.30% 69.30% -0.01%
==========================================
Files 502 502
Lines 51632 51637 +5
==========================================
+ Hits 35786 35788 +2
- Misses 13077 13084 +7
+ Partials 2769 2765 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR makes TestMonitoredTokenSource_SingleflightDeduplicatesConcurrentRetries deterministic by adding two test-only synchronization hooks around the singleflight entry/leader execution, preventing late-arriving goroutines from starting independent retry loops.
Changes:
- Added
beforeSingleflightEntryandafterSingleflightEntry(nil in production) to coordinate concurrent callers in tests. - Wired these hooks into
MonitoredTokenSource.Token()aroundrefreshGroup.Do. - Rewrote the flaky singleflight retry deduplication test to use a two-phase barrier and tightened the expected call-count assertion.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/auth/monitored_token_source.go | Adds two optional hooks and invokes them around the singleflight boundary to enable deterministic test synchronization. |
| pkg/auth/monitored_token_source_test.go | Updates the concurrent retry deduplication test to use a two-phase barrier and assert exact underlying call counts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4801741 to
b73060b
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
TestMonitoredTokenSource_SingleflightDeduplicatesConcurrentRetries was non-deterministic: the singleflight leader could complete its retry and return before follower goroutines reached refreshGroup.Do, causing them to start independent retry loops and fail the call-count assertion. Add beforeSingleflightEntry and afterSingleflightEntry test hooks (both nil in production) to MonitoredTokenSource. The test uses a two-phase barrier: - Phase 1 (beforeSingleflightEntry): all goroutines rendezvous and are released simultaneously toward refreshGroup.Do. - Phase 2 (afterSingleflightEntry): the leader waits inside Do until all goroutines have signalled they are about to call Do, guaranteeing the group is fully formed before the retry returns.
b73060b to
8496fa6
Compare
Summary
TestMonitoredTokenSource_SingleflightDeduplicatesConcurrentRetrieswas non-deterministic: after a barrier released all goroutines towardrefreshGroup.Do, the singleflight leader could complete its retry and return before follower goroutines reachedDo— causing each follower to start an independent retry loop and fail the call-count assertion.The fix also addresses a design smell: the singleflight/retry logic and its test hooks were embedded in
MonitoredTokenSource, making that struct own too many concerns.Changes:
transientRefresher— a small, focused type that owns thesingleflight.Group, exponential-backoff retry, and the two synchronisation hooks (beforeEntry,afterEntry). Nil in production; set in tests only.MonitoredTokenSourcenow holds a*transientRefresherand delegates transient-error handling torefresher.Refresh(). The three test hooks (beforeEntry,afterEntry,newRetryBackOff) are removed from the production struct.TestTransientRefresher_SingleflightDeduplicatesConcurrentRetries, targetingtransientRefresherdirectly with the two-phase barrier. NoMonitoredTokenSourceor status-updater mock needed. Key assertion simplifies to exactly 1tokenSource.Token()call (only the singleflight leader retries).callCountinsidetokenFnwould require re-acquiring the mock's mutex and deadlock (it would not — the mutex is already held).Type of change
Test plan
task test)task test-e2e)task lint-fix)Changes
pkg/auth/monitored_token_source.gotransientRefresherwithRefresh,retry,getBackOff;MonitoredTokenSourcedelegates to it, test hooks removedpkg/auth/monitored_token_source_test.gotransientRefresherdirectly; update remaining tests to useats.refresher.newBackOff; fix misleading comment; remove unusedsync/atomicimportDoes this introduce a user-facing change?
No.