Skip to content

test(csharp): de-flake FeatureFlagCache single-external-call (assert dedup) - #630

Closed
eric-wang-1990 wants to merge 1 commit into
mainfrom
fix/deflake-featureflag-cache-dedup
Closed

test(csharp): de-flake FeatureFlagCache single-external-call (assert dedup)#630
eric-wang-1990 wants to merge 1 commit into
mainfrom
fix/deflake-featureflag-cache-dedup

Conversation

@eric-wang-1990

Copy link
Copy Markdown
Collaborator

What

De-flakes FeatureFlagCacheE2ETest.TestFeatureFlagCache_SingleExternalCallAcrossConnections by asserting the cache dedups rather than demanding exactly 1 external fetch.

Why

The test opens 5 connections to the same host and asserted Assert.Equal(1, fetchCount). That's too strict:

  • Healthy fetch → 15-min sliding TTL → all 5 connections share one fetch → 1 (the usual pass).
  • If the first fetch hits a transient failure/timeout, it's cached with a short 60s negative TTL (FeatureFlagContext.DefaultNegativeTtl) by design, so a later connection re-fetches → 2.

The cache is still deduping in both cases (3–4 of 5 served from cache); the negative-cache retry is a feature. The exact-1 assertion turned that designed-in retry into a flake — observed Expected: 1 / Actual: 2 in a merge-queue run of #627 (job 92235923069). History confirms it's low-rate: this test passed the other recent runs and failed once, Actual always 2 (never higher).

Fix

Assert dedup: fetchCount >= 1 && fetchCount < connectionCount && fetchCount <= 2 — one initial fetch plus at most one transient negative-cache re-fetch. Still fails loudly if the cache genuinely stops deduping (fetchCount ≈ connectionCount), while tolerating a single environmental hiccup.

This pull request and its description were written by Isaac.

…dedup)

TestFeatureFlagCache_SingleExternalCallAcrossConnections asserted EXACTLY one
external feature-flag fetch across 5 connections. That is too strict: healthy
fetches get a 15-min sliding TTL (all 5 share one fetch → 1), but if the FIRST
fetch hits a transient failure/timeout it is cached with a short 60s NEGATIVE TTL
(FeatureFlagContext.DefaultNegativeTtl) BY DESIGN, so a later connection re-fetches
→ 2. The cache is still deduping (3-4 of 5 served from cache); the exact-1 assertion
turned that designed-in retry into a flake (observed Expected 1 / Actual 2, once,
in a merge-queue run of #627).

Assert DEDUP instead of exact-1: fetchCount >= 1, < connectionCount, and <= 2 (one
initial fetch, plus at most one transient negative-cache re-fetch). This still fails
loudly if the cache genuinely stops deduping (fetchCount ~= connectionCount) while
tolerating a single environmental hiccup.

Co-authored-by: Isaac

@peco-review-bot peco-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: 1 Low

Looks good — a sound, test-only de-flake that relaxes an over-strict == 1 assertion to a dedup check (>= 1 && < connectionCount && <= 2), with clear rationale in the comment. One low: the test's <summary> docstring still claims "exactly one" external fetch and now contradicts the new assertion.


// Assert - exactly one external call; the rest served from the shared cache.
Assert.Equal(1, fetchCount);
// Assert - the shared cache DEDUPS: far fewer external fetches than connections.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Low — The <summary> docstring for this test still asserts the old, now-removed contract: it says opening multiple connections "results in exactly one actual connector-service fetch; the rest are served from the cache." The body of the PR deliberately relaxes that to tolerate a second fetch under the negative-cache TTL. The docstring now contradicts the assertion (fetchCount <= 2) directly below it. Consider updating it to describe dedup ("at most 2 fetches") so the stated contract matches the code.

The test method name TestFeatureFlagCache_SingleExternalCallAcrossConnections is similarly stale, but renaming it is optional churn; the docstring is the clearer fix.

(Anchored to the nearest changed line — see the description for the exact location.)

@eric-wang-1990

Copy link
Copy Markdown
Collaborator Author

Consolidated into #629 — the FeatureFlagCache dedup fix is now the second commit on that branch, so both E2E de-flakes land together. Closing this in favor of #629.

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