-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
test(node): Automatically run all node-integration tests with orchestrion #21911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+178
−150
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
17 changes: 0 additions & 17 deletions
17
dev-packages/node-integration-tests/suites/tracing/lru-memoizer/instrument-orchestrion.mjs
This file was deleted.
Oops, something went wrong.
126 changes: 41 additions & 85 deletions
126
dev-packages/node-integration-tests/suites/tracing/lru-memoizer/test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,103 +1,59 @@ | ||
| import { afterAll, describe, expect } from 'vitest'; | ||
| import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner'; | ||
| import { createCjsTests } from '../../../utils/runner/createEsmAndCjsTests'; | ||
| import { isOrchestrionEnabled } from '../../../utils'; | ||
|
|
||
| describe('lru-memoizer', () => { | ||
| afterAll(() => { | ||
| cleanupChildProcesses(); | ||
| }); | ||
|
|
||
| // Each case maps to the OpenTelemetry default and the diagnostics-channel opt-in | ||
| // variants, mirroring the mysql suite. `flags` are extra Node CLI flags; the | ||
| // instrument file is always loaded via `--import` (esm) / `--require` (cjs). | ||
| // | ||
| // lru-memoizer creates no spans, so there's no `sentry.origin` to | ||
| // assert: the opt-in cases prove the channel ran because the opt-in removes the | ||
| // OTel integration via `replacedOtelIntegrationNames`. | ||
| const CASES = [ | ||
| // OpenTelemetry default — no opt-in, no injection. (OTel does not support ESM.) | ||
| { label: 'opentelemetry (default)', instrument: 'instrument.mjs', flags: [], failsOnEsm: true }, | ||
| // Opt-in via init only. `Sentry.init()` injects the channels synchronously. | ||
| { | ||
| label: 'diagnostics-channel (init opt-in)', | ||
| instrument: 'instrument-orchestrion.mjs', | ||
| flags: [], | ||
| failsOnEsm: false, | ||
| }, | ||
| // Opt-in and rely on `node --import @sentry/node/import`. | ||
| { | ||
| label: 'diagnostics-channel (--import @sentry/node/import opt-in)', | ||
| instrument: 'instrument-orchestrion.mjs', | ||
| flags: ['--import', '@sentry/node/import'], | ||
| failsOnEsm: false, | ||
| }, | ||
| // Without opt-in: channels are injected unconditionally but not subscribed to, | ||
| // so the OTel instrumentation does the work — proves injecting the channels has | ||
| // no downside. (OTel does not support ESM.) | ||
| { | ||
| label: 'opentelemetry (channels injected, no opt-in)', | ||
| instrument: 'instrument.mjs', | ||
| flags: ['--import', '@sentry/node/import'], | ||
| failsOnEsm: true, | ||
| }, | ||
| ] as const; | ||
|
|
||
| for (const { label, instrument, flags, failsOnEsm } of CASES) { | ||
| describe(label, () => { | ||
| createEsmAndCjsTests( | ||
| __dirname, | ||
| 'scenario.mjs', | ||
| instrument, | ||
| (createTestRunner, test) => { | ||
| test('keeps outer context inside the memoized inner functions', async () => { | ||
| await createTestRunner() | ||
| .withFlags(...flags) | ||
| .expect({ | ||
| transaction: { | ||
| transaction: '<unknown>', | ||
| contexts: { | ||
| trace: expect.objectContaining({ | ||
| op: 'run', | ||
| data: expect.objectContaining({ | ||
| 'sentry.op': 'run', | ||
| 'sentry.origin': 'manual', | ||
| 'memoized.context_preserved': true, | ||
| }), | ||
| }), | ||
| }, | ||
| }, | ||
| }) | ||
| .start() | ||
| .completed(); | ||
| }); | ||
| }, | ||
| { failsOnEsm }, | ||
| ); | ||
|
|
||
| // CJS-only: the parallel scenario is flaky in ESM (see #21729). | ||
| createCjsTests(__dirname, 'scenario-parallel.mjs', instrument, (createTestRunner, test) => { | ||
| test('keeps each span context across parallel memoized requests', async () => { | ||
| // Each parallel request emits a transaction whose callback must have run in its own context. | ||
| // Two identical expectations keep this order-independent. | ||
| const expectation = { | ||
| createEsmAndCjsTests( | ||
| __dirname, | ||
| 'scenario.mjs', | ||
| 'instrument.mjs', | ||
| (createTestRunner, test) => { | ||
| test('keeps outer context inside the memoized inner functions', async () => { | ||
| await createTestRunner() | ||
| .expect({ | ||
| transaction: { | ||
| transaction: '<unknown>', | ||
| contexts: { | ||
| trace: expect.objectContaining({ | ||
| op: expect.stringMatching(/^(first|second)$/), | ||
| data: expect.objectContaining({ 'memoized.context_preserved': true }), | ||
| op: 'run', | ||
| data: expect.objectContaining({ | ||
| 'sentry.op': 'run', | ||
| 'sentry.origin': 'manual', | ||
| 'memoized.context_preserved': true, | ||
| }), | ||
| }), | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| await createTestRunner() | ||
| .withFlags(...flags) | ||
| .expect(expectation) | ||
| .expect(expectation) | ||
| .start() | ||
| .completed(); | ||
| }); | ||
| }) | ||
| .start() | ||
| .completed(); | ||
| }); | ||
| }, | ||
| { failsOnEsm: !isOrchestrionEnabled() }, | ||
| ); | ||
|
|
||
| // CJS-only: the parallel scenario is flaky in ESM (see #21729). | ||
| createCjsTests(__dirname, 'scenario-parallel.mjs', 'instrument.mjs', (createTestRunner, test) => { | ||
| test('keeps each span context across parallel memoized requests', async () => { | ||
| // Each parallel request emits a transaction whose callback must have run in its own context. | ||
| // Two identical expectations keep this order-independent. | ||
| const expectation = { | ||
| transaction: { | ||
| contexts: { | ||
| trace: expect.objectContaining({ | ||
| op: expect.stringMatching(/^(first|second)$/), | ||
| data: expect.objectContaining({ 'memoized.context_preserved': true }), | ||
| }), | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| await createTestRunner().expect(expectation).expect(expectation).start().completed(); | ||
| }); | ||
| } | ||
| }); | ||
| }); |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: This can be removed, seems to be a duplicate from the
utils/index.tsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is needed for usage in scenario usage where you need to do e.g.
import { isOrchestrionEnabled } from '@sentry-internal/node-integration-tests'while the one in utils is for in-test usage. at least this is our current differentiation, not 100% sure if we need this 😅