Skip to content

Commit df71818

Browse files
committed
fix(telemetry): e2e suite singleton reset + relaxed flush-on-close assert
CI on the previous commit showed two e2e failures driven by state that leaks across e2e test files, not by real defects: 1. `should initialize telemetry when telemetryEnabled is true` — `featureFlagCacheSpy.called` was false because a prior e2e suite had already created a TelemetryClient for the test host. Subsequent `getOrCreateClient` calls hit the existing holder and skip the constructor (and the FFCache.getOrCreateContext call inside it). Fixed by `before` + `beforeEach` `__resetInstanceForTests()` so this suite always sees a fresh provider regardless of execution order. That also clears the "second context, different auth" F4 warn that was firing on every test in this suite. 2. `should cleanup telemetry on close` — `MetricsAggregator.flush()` isn't called by the close-drain when `pendingMetrics` is empty (the test connects + closes without ever `openSession`-ing, so no events are queued). Replaced the strict `flushSpy.called` assert with `aggregatorCloseSpy.called` — `MetricsAggregator.close()` is the cleanup surface that always runs, regardless of buffer state. Also: change the outer `describe` from `function ()` to arrow form (eslint `prefer-arrow-callback`); only `before`/`it` need the function-form for `this`. Co-authored-by: Isaac Signed-off-by: samikshya-chand_data <samikshya.chand@databricks.com>
1 parent 44bb38f commit df71818

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

tests/e2e/telemetry/telemetry-integration.test.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,30 @@ function loadConfigOrSkip(suite: Mocha.Suite): TestConfig | null {
7171
return cfg as TestConfig;
7272
}
7373

74-
describe('Telemetry Integration', function () {
74+
describe('Telemetry Integration', () => {
7575
let config: TestConfig | null = null;
7676

77+
// The e2e test runner executes many suites before this one; any earlier
78+
// DBSQLClient connect leaves a TelemetryClient in the process-wide singleton
79+
// for the test host. Reset before our first test so the FF cache and
80+
// refcount spies in this suite observe a clean lineage.
7781
before(function () {
7882
config = loadConfigOrSkip(this.test!.parent!);
7983
if (!config) {
8084
this.skip();
85+
return;
8186
}
87+
TelemetryClientProvider.__resetInstanceForTests();
8288
});
8389

8490
// Reset the process-wide singleton between tests so refcount + cached
85-
// feature flags from one test don't leak into the next.
91+
// feature flags from one test don't leak into the next. Combined with the
92+
// `before` reset above, every test sees a fresh provider regardless of
93+
// what other e2e suites did first.
94+
beforeEach(() => {
95+
TelemetryClientProvider.__resetInstanceForTests();
96+
});
97+
8698
afterEach(() => {
8799
TelemetryClientProvider.__resetInstanceForTests();
88100
sinon.restore();
@@ -222,7 +234,7 @@ describe('Telemetry Integration', function () {
222234
const client = new DBSQLClient();
223235

224236
const releaseClientSpy = sinon.spy(TelemetryClientProvider.prototype, 'releaseClient');
225-
const flushSpy = sinon.spy(MetricsAggregator.prototype, 'flush');
237+
const aggregatorCloseSpy = sinon.spy(MetricsAggregator.prototype, 'close');
226238

227239
try {
228240
await client.connect({
@@ -234,15 +246,19 @@ describe('Telemetry Integration', function () {
234246

235247
await client.close();
236248

237-
// All three must happen on a clean close: releaseClient is the
238-
// refcount surface; flush is the drain. Previously a disjunction
239-
// (`||`) over multiple spies meant any single one firing satisfied
240-
// the test — a regression that broke ONE of them would still pass.
249+
// releaseClient is the refcount surface; MetricsAggregator.close is
250+
// the cleanup the last refcount holder triggers. Both must fire on a
251+
// clean close. We do NOT assert flush() was called because this test
252+
// never `openSession`s, so the pending-metrics buffer is empty and
253+
// the close-drain pattern legitimately skips the final flush. The
254+
// previous disjunction (`releaseClient || flush || releaseContext`)
255+
// over multiple spies meant a regression breaking one would still
256+
// pass — these explicit asserts catch that.
241257
expect(releaseClientSpy.called, 'releaseClient should be called on close').to.be.true;
242-
expect(flushSpy.called, 'aggregator flush should run on close').to.be.true;
258+
expect(aggregatorCloseSpy.called, 'MetricsAggregator.close should run on close').to.be.true;
243259
} finally {
244260
releaseClientSpy.restore();
245-
flushSpy.restore();
261+
aggregatorCloseSpy.restore();
246262
}
247263
});
248264
});

0 commit comments

Comments
 (0)