Skip to content

Commit 45db4dd

Browse files
committed
test(telemetry): drop warn-mock assertions for behavior-only tests
Aligns the older `setProperty`/`setMeasurement` post-emit test with the new log/logError and phase tests: assert on observable behavior (no event leak, fn still runs) rather than on `logger.warn` mock calls. The warn itself is a developer aid for escaped-span bugs and stays in production; only the test coupling is removed. Brief comment added on `warnPostEmit` to record the intent.
1 parent b81550b commit 45db4dd

2 files changed

Lines changed: 2 additions & 18 deletions

File tree

src/telemetry/service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ export class TelemetryService implements vscode.Disposable, TelemetryReporter {
176176
let completed = false;
177177
// `markFailure` wins over `markAborted` regardless of call order.
178178
let mark: "aborted" | "error" | undefined;
179+
// Surfaces escaped-span bugs in the dev console. The drop is tested; the warn is not.
179180
const warnPostEmit = (op: string, name: string): void => {
180181
this.logger.warn(
181182
`Telemetry span '${eventName}' ${op}('${name}') called after emit; mutation dropped`,

test/unit/telemetry/service.test.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -370,40 +370,23 @@ describe("TelemetryService", () => {
370370
expect(phase.eventName).toBe("op.bad_name");
371371
});
372372

373-
it("warns and ignores setProperty/setMeasurement called after emit", async () => {
373+
it("drops setProperty/setMeasurement/markAborted/markFailure called after emit", async () => {
374374
let escapedSpan: Span | undefined;
375375
await h.service.trace("op", (span) => {
376376
escapedSpan = span;
377377
return Promise.resolve();
378378
});
379379

380380
expect(h.sink.events).toHaveLength(1);
381-
const warnBefore = vi.mocked(h.logger.warn).mock.calls.length;
382381

383382
escapedSpan?.setProperty("late", "ignored");
384383
escapedSpan?.setMeasurement("lateMs", 99);
385384
escapedSpan?.markAborted();
386385
escapedSpan?.markFailure();
387386

388-
// Mutations dropped: emitted event is unchanged.
389387
expect(h.sink.events[0].properties.late).toBeUndefined();
390388
expect(h.sink.events[0].measurements.lateMs).toBeUndefined();
391389
expect(h.sink.events[0].properties.result).toBe("success");
392-
393-
// Each post-emit mutation logs a warning.
394-
expect(vi.mocked(h.logger.warn).mock.calls.length).toBe(warnBefore + 4);
395-
expect(vi.mocked(h.logger.warn).mock.calls[warnBefore][0]).toContain(
396-
"setProperty",
397-
);
398-
expect(vi.mocked(h.logger.warn).mock.calls[warnBefore + 1][0]).toContain(
399-
"setMeasurement",
400-
);
401-
expect(vi.mocked(h.logger.warn).mock.calls[warnBefore + 2][0]).toContain(
402-
"markAborted",
403-
);
404-
expect(vi.mocked(h.logger.warn).mock.calls[warnBefore + 3][0]).toContain(
405-
"markFailure",
406-
);
407390
});
408391

409392
it("drops span logs called after emit", async () => {

0 commit comments

Comments
 (0)