fix(node): fix flaky nestjs interceptor test#3293
Merged
marandaneto merged 1 commit intomainfrom Mar 27, 2026
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📝 No Changeset FoundThis PR doesn't include a changeset. A changeset (and the release label) is required to release a new version. How to add a changesetRun this command and follow the prompts: pnpm changesetRemember: Never use |
Contributor
Important Files Changed
Prompt To Fix All With AIThis is a comment left during a code review.
Path: packages/node/src/__tests__/extensions/nestjs.spec.ts
Line: 77-79
Comment:
**Redundant double-shutdown per test**
`waitForFlushTimer(posthog)` now calls `posthog.shutdown()`, but `afterEach` also calls `posthog.shutdown()`. For every test that invokes `waitForFlushTimer`, the instance is shut down twice sequentially.
The SDK docs explicitly note: *"Do not use this function if you intend to keep using this PostHog instance after calling it."* While the second call is harmless in practice (it finds an empty queue and returns quickly), it goes against the intended single-use contract and causes unnecessary work.
One clean option is to remove the `afterEach` cleanup entirely — since every test that captures events already shuts down via `waitForFlushTimer`, and tests that don't capture events leave nothing to clean up. Alternatively, keep `shutdown()` only in `afterEach` and use a different drain mechanism in `waitForFlushTimer`.
How can I resolve this? If you propose a fix, please make it concise.Reviews (2): Last reviewed commit: "fix(node): fix flaky nestjs interceptor ..." | Re-trigger Greptile |
b4cc0c2 to
9667f6c
Compare
Contributor
Contributor
|
Size Change: 0 B Total Size: 6.57 MB ℹ️ View Unchanged
|
dustinbyrne
approved these changes
Mar 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The NestJS interceptor test
should capture exception with correct propertiesis flaky in CI. ThecaptureExceptionpath adds a pending promise with an async chain (buildEventMessageresolves stack frames →.then(capture)). The oldwaitForFlushTimerhelper relied on a fragile combination ofwaitForPromises()andjest.runOnlyPendingTimers()that could race with the async chain.Changes
Replaced the non-deterministic
waitForFlushTimerwith a deterministic approach usingposthog.shutdown(), which callspromiseQueue.join()to drain all pending promises before flushing. This guarantees that async chains likecaptureException'sbuildEventMessage().then(capture)are fully resolved before asserting on the batch output.waitForPromisesimportwaitForFlushTimernow takes theposthoginstance and callsshutdown()Release info Sub-libraries affected
Libraries affected
Checklist