Skip to content

Commit fb23878

Browse files
mydeaclaude
andauthored
test(node): Auto-flush node-integration-tests via beforeExit (#20960)
Removes the `setInterval(() => {}, 1000)` boilerplate from 46 integration-test scenarios by injecting a `beforeExit` auto-flush hook from the runner instead. **Why the boilerplate existed.** Most scenarios end synchronously after queuing spans/events. The OTel batch processor and Sentry client flush asynchronously, so without a live handle Node exits before envelopes reach the (logging) transport. Each scenario kept the loop alive with a `setInterval`; the runner SIGTERMed the child once it had seen the expected envelopes. **What replaces it.** A small `auto-flush.{cjs,mjs}` loader injected via `--require` / `--import` registers a `process.on('beforeExit', () => Sentry.flush(2000))`. When the loop drains, the awaited flush keeps it alive until queued envelopes are sent, then the process exits naturally — no setInterval, no SIGTERM handler interaction, no force-exit timer. Two loader variants because Node's CJS and ESM module caches are separate: ESM scenarios get `auto-flush.mjs` so `import * as Sentry` resolves to the same SDK instance the scenario uses; CJS gets `auto-flush.cjs`. The runner picks the right one based on whether `flags` already contain `--import`. Skipped when no envelopes are expected (e.g. ANR `should-exit`, `ensureNoErrorOutput`) — those tests assert the child exits naturally and auto-flush would delay them by retrying HTTP requests against the fake DSN. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 11a20b6 commit fb23878

44 files changed

Lines changed: 74 additions & 124 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dev-packages/node-integration-tests/suites/tracing/amqplib/scenario.mjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ const QUEUE_OPTIONS = {
3232

3333
await channel.close();
3434
await connection.close();
35-
36-
// Stop the process from exiting before the transaction is sent
37-
setInterval(() => {}, 1000);
3835
})();
3936

4037
async function connectToRabbitMQ() {

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/scenario-error.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ Sentry.init({
88
transport: loggingTransport,
99
});
1010

11-
// Stop the process from exiting before the transaction is sent
12-
setInterval(() => {}, 1000);
13-
1411
async function run() {
1512
const gql = require('graphql-tag');
1613
const server = require('./apollo-server')();

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/scenario-mutation.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ Sentry.init({
88
transport: loggingTransport,
99
});
1010

11-
// Stop the process from exiting before the transaction is sent
12-
setInterval(() => {}, 1000);
13-
1411
async function run() {
1512
const gql = require('graphql-tag');
1613
const server = require('./apollo-server')();

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/scenario-query.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ Sentry.init({
88
transport: loggingTransport,
99
});
1010

11-
// Stop the process from exiting before the transaction is sent
12-
setInterval(() => {}, 1000);
13-
1411
async function run() {
1512
const server = require('./apollo-server')();
1613

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/useOperationNameForRootSpan/scenario-invalid-root-span.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ const client = Sentry.init({
1111

1212
const tracer = client.tracer;
1313

14-
// Stop the process from exiting before the transaction is sent
15-
setInterval(() => {}, 1000);
16-
1714
async function run() {
1815
const server = require('../apollo-server')();
1916

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/useOperationNameForRootSpan/scenario-multiple-operations-many.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ const client = Sentry.init({
1111

1212
const tracer = client.tracer;
1313

14-
// Stop the process from exiting before the transaction is sent
15-
setInterval(() => {}, 1000);
16-
1714
async function run() {
1815
const server = require('../apollo-server')();
1916

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/useOperationNameForRootSpan/scenario-multiple-operations.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ const client = Sentry.init({
1111

1212
const tracer = client.tracer;
1313

14-
// Stop the process from exiting before the transaction is sent
15-
setInterval(() => {}, 1000);
16-
1714
async function run() {
1815
const server = require('../apollo-server')();
1916

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/useOperationNameForRootSpan/scenario-mutation.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ const client = Sentry.init({
1111

1212
const tracer = client.tracer;
1313

14-
// Stop the process from exiting before the transaction is sent
15-
setInterval(() => {}, 1000);
16-
1714
async function run() {
1815
const gql = require('graphql-tag');
1916
const server = require('../apollo-server')();

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/useOperationNameForRootSpan/scenario-no-operation-name.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ const client = Sentry.init({
1111

1212
const tracer = client.tracer;
1313

14-
// Stop the process from exiting before the transaction is sent
15-
setInterval(() => {}, 1000);
16-
1714
async function run() {
1815
const server = require('../apollo-server')();
1916

dev-packages/node-integration-tests/suites/tracing/apollo-graphql/useOperationNameForRootSpan/scenario-query.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ const client = Sentry.init({
1111

1212
const tracer = client.tracer;
1313

14-
// Stop the process from exiting before the transaction is sent
15-
setInterval(() => {}, 1000);
16-
1714
async function run() {
1815
const server = require('../apollo-server')();
1916

0 commit comments

Comments
 (0)