Skip to content

Stop a telemetry test from failing the frontend test run - #4809

Merged
reakaleek merged 1 commit into
mainfrom
fix-otel-test-timer-leak
Nov 13, 2026
Merged

reakaleek merged 1 commit into
mainfrom
fix-otel-test-timer-leak

Conversation

@reakaleek

Copy link
Copy Markdown
Member

The npm CI job no longer fails on an unhandled ReferenceError: document is not defined after all tests pass. A telemetry test leaked a timer into later test files.

Affects: Internals only

Prompt summary: CI is red on an unrelated PR. Find out why the npm job fails and fix it.

Why

does not read document.cookie while the real SDK starts runs the real EDOT browser SDK. Under jsdom, the navigation timing instrumentation never sees a finished page load, so it retries on a backoff timer. When the same Vitest worker runs another file afterwards, the timer fires against a torn-down environment. Vitest then reports an unhandled error and the job exits with code 1. This fails main at 17b002443, and whether it fails depends on how CI spreads files across workers.

What

The test runs on fake timers

The test now calls vi.useFakeTimers() before it starts the real SDK and restores real timers in a finally. The pending retry is a fake timer, so it goes away with the test. Calling shutdown() on the SDK does not work, because it waits on an export that never finishes under jsdom.

Verify

cd src/Elastic.Documentation.Site
npx vitest run --maxWorkers=1 --no-file-parallelism Assets/telemetry Assets/web-components/AskAi
# before: "Errors 1 error" with ReferenceError: document is not defined; after: no errors

🤖 Generated with Claude Code

…iles

The test starts the real EDOT SDK. Under jsdom, its navigation timing instrumentation retries on a backoff timer. When the worker runs another file after this one, the timer fires against a torn-down environment and Vitest fails the run with `document is not defined`. The test now runs on fake timers, so the pending retry goes away with the test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@reakaleek
reakaleek requested a review from a team as a code owner November 10, 2026 18:04
@reakaleek reakaleek added the bug label Nov 10, 2026
@reakaleek
reakaleek requested a review from akira28 November 10, 2026 18:04
@github-actions

Copy link
Copy Markdown
Contributor

@reakaleek
reakaleek merged commit 8dce0e8 into main Nov 13, 2026
48 checks passed
@reakaleek
reakaleek deleted the fix-otel-test-timer-leak branch November 13, 2026 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants