Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #40619
This commit fixes the flakiness in TestCredentialsCache (for real this time).
The cache runs a loop in a goroutine that waits on a ticker and refreshes credentials as necessary based on some criteria. This is a design choice that makes the credential cache able to tolerate brief outages of the Teleport Proxy or AWS STS even if they happen to coincide with the time the credential would usually be refreshed.
The test repeatedly advances a fake clock and makes sure that the credential cache is able/not able to get creds as expected. The flakiness arises when the testcase advances the clock before the run loop gets a chance to create the ticker and wait on it. This is solved by waiting to advance the clock until there is at least one goroutine waiting on the clock.
The test now passes 50000 times in a docker container with 0.25 cpus and 100000 times on my laptop. Without the fix it usually failed within around 5000 runs.