Skip to content

Fix flaky ATM test for cached tokens over the max length - #377

Merged
pgermishuys merged 1 commit into
mainfrom
pg/atm-wait-for-shared-cache-write
Oct 16, 2026
Merged

pgermishuys merged 1 commit into
mainfrom
pg/atm-wait-for-shared-cache-write

Conversation

@pgermishuys

Copy link
Copy Markdown
Contributor

Instance_with_lower_limit_is_served_the_cached_token_written_by_another_instance (from #367) fails now and then. It failed once on main (the #366 merge), and most of the time on the 4.3.x backports, where CI runs the net8.0, net9.0 and net10.0 test hosts side by side.

HybridCache hands the token to the caller first and writes it to the distributed cache afterwards, in the background. The test started instance B as soon as instance A returned, so B could look in the shared cache before A's write landed. B then fetched its own token, and the assertion saw TokenRequestsByB = 1, Lengths = 100,100,100. The test now waits for A's write before it starts B.

To confirm the cause, I delayed the shared cache write by 200 ms locally: the test failed the same way every time without this change and passed with it.

Once this is merged I'll cherry-pick it into the 4.3.x backport of #367 (#371).

HybridCache returns the token to the caller and then writes it to the distributed cache in the background. The test started instance B straight after instance A returned, so on a busy CI runner B could read the shared cache before A's write landed, fetch its own token and fail. The test now waits for A's write before it starts B.
@pgermishuys pgermishuys added the area/foss/atm Issues related to Access Token Management label Oct 16, 2026
Copilot AI balanced review requested due to automatic review settings October 16, 2026 12:48

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.

🟢 Approval recommended

The targeted test-only synchronization addresses the reported race without changing production behavior.

0 open findings

What changed in this PR

Fixes the flaky cross-instance token-cache test by waiting for instance A’s distributed-cache write before starting instance B.

Changes:

  • Signals completion after synchronous and asynchronous cache writes.
  • Waits for that signal with a timeout and cancellation support.
File Description
access-token-management/​test/​AccessTokenManagement.Tests/​ClientTokenManagementTests.cs Synchronizes the test with cache-write completion to remove the race.

🧠 Review effort: Balanced


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

@pgermishuys
pgermishuys merged commit 04586d6 into main Oct 16, 2026
4 checks passed
@pgermishuys
pgermishuys deleted the pg/atm-wait-for-shared-cache-write branch October 16, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/foss/atm Issues related to Access Token Management

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants