Skip to content

Commit 1991121

Browse files
committed
test(telemetry): de-flake FeatureFlagCache placeholder test (network seam)
The "fetchFeatureFlag should return false as placeholder implementation" test called the real fetchFeatureFlag, which makes an HTTP call via fetchWithRetry (10s timeout) to a bogus host. Under mocha's 2s default it only passed when the DNS failure happened to resolve quickly — flaky across runners and Node versions (it timed out on Node 14/16/18 in CI, fail-fast-canceling the rest of the matrix; Node 20 passed). Stub the fetchWithRetry network seam so the test deterministically exercises the behavior under test (fetchFeatureFlag resolves to false) with no real network call. No production code change. Co-authored-by: Isaac Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
1 parent 2f8eece commit 1991121

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

tests/unit/telemetry/FeatureFlagCache.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,19 @@ describe('FeatureFlagCache', () => {
257257
const cache = new FeatureFlagCache(context);
258258
const host = 'test-host.databricks.com';
259259

260+
// Stub the network seam so the test is deterministic. The real
261+
// `fetchWithRetry` makes an HTTP call with a 10s timeout to the
262+
// (bogus) host; under mocha's 2s default this passed only when the
263+
// DNS failure happened to resolve quickly — flaky across runners /
264+
// Node versions (it timed out on Node 14/16/18 in CI). The behavior
265+
// under test is just that `fetchFeatureFlag` resolves to `false`.
266+
const fetchStub = sinon.stub(cache as any, 'fetchWithRetry').rejects(new Error('network disabled in test'));
267+
260268
// Access private method through any cast
261269
const result = await (cache as any).fetchFeatureFlag(host);
262270
expect(result).to.be.false;
271+
272+
fetchStub.restore();
263273
});
264274
});
265275

0 commit comments

Comments
 (0)