Skip to content

[common.oauth] Fix flaky TestNewTokenSource - #1522

Merged
manugarg merged 1 commit into
mainfrom
oauth-test-flaky-counter
Oct 4, 2026
Merged

manugarg merged 1 commit into
mainfrom
oauth-test-flaky-counter

Conversation

@manugarg

@manugarg manugarg commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

`TestNewTokenSource` fails now and then with:

--- FAIL: TestNewTokenSource/Refresh_fails,_go_with_the_cache:file:_"f_fail"_refresh_interval_sec:_1
    tokensource_test.go:188: newTokenSource() error = failed_reading_token, wantErr false

The test's call counter was one global, and a token source's refresh goroutine never stops. The "Refresh in 1s" subtest waits 3s, which is exactly when its 1s ticker fires again. That leftover goroutine could bump the counter right after the next subtest reset it, and the next subtest's first fetch then took the "counter > 0, fail" path.

This counts calls per config, i.e. per token source, so the goroutines of earlier subtests can't affect later ones. Test-only change.

Tested with `go test ./common/oauth -race`: 1 failure in 6 runs before, 20 of 20 passing after.

The test's call counter was one global, and a token source's refresh
goroutine never stops. The "Refresh in 1s" subtest waits 3s, which is
when its 1s ticker fires again, so that goroutine could bump the counter
right after the next subtest reset it. That subtest's first fetch then
failed with failed_reading_token.

Count calls per config, i.e. per token source, instead.
@manugarg
manugarg merged commit 2c6efbc into main Oct 4, 2026
13 checks passed
@manugarg
manugarg deleted the oauth-test-flaky-counter branch October 4, 2026 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant