Skip to content

Commit d0e644f

Browse files
authored
test(integration): use stopProc in package tests (#7839)
Replace direct proc.kill() teardown in package-hosted integration specs with await stopProc(proc). This makes process shutdown consistent with the root integration tests and reduces flakiness from leaked child process state. Add an optional signal to preserve the existing SIGINT-based Azure teardown behavior.
1 parent 122c405 commit d0e644f

File tree

97 files changed

+322
-155
lines changed

Some content is hidden

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

97 files changed

+322
-155
lines changed

integration-tests/helpers/index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,21 +265,25 @@ function spawnProcAndExpectExit (filename, options = {}, stdioHandler, stderrHan
265265
/**
266266
* Stop a process and wait for it to fully exit.
267267
*
268-
* Sends `SIGTERM` first, waits up to `timeoutMs`, and escalates to `SIGKILL` if needed.
268+
* Sends `signal` first, waits up to `timeoutMs`, and escalates to `SIGKILL` if needed.
269269
*
270270
* @param {childProcess.ChildProcess|undefined} proc - Process to stop.
271271
* @param {object} [options] - Stop options.
272+
* @param {NodeJS.Signals} [options.signal='SIGTERM'] - Signal to send before escalating.
272273
* @param {number} [options.timeoutMs=defaultStopProcTimeoutMs] - Max wait per signal in milliseconds.
273274
* @returns {Promise<void>}
274275
*/
275-
async function stopProc (proc, { timeoutMs = defaultStopProcTimeoutMs } = {}) {
276+
async function stopProc (proc, options = {}) {
276277
if (!proc) return
277278
if (proc.exitCode !== null || proc.signalCode !== null) return
278279

279-
proc.kill()
280+
const signal = options.signal ?? 'SIGTERM'
281+
const timeoutMs = options.timeoutMs ?? defaultStopProcTimeoutMs
280282

281-
const exitedAfterSigterm = await waitForProcExit(proc, timeoutMs)
282-
if (exitedAfterSigterm) return
283+
proc.kill(signal)
284+
285+
const exitedAfterInitialSignal = await waitForProcExit(proc, timeoutMs)
286+
if (exitedAfterInitialSignal) return
283287

284288
proc.kill('SIGKILL')
285289
const exitedAfterSigkill = await waitForProcExit(proc, timeoutMs)

packages/datadog-plugin-ai/test/integration-test/client.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
useSandbox,
1010
spawnPluginIntegrationTestProcAndExpectExit,
1111
varySandbox,
12+
stopProc,
1213
} = require('../../../../integration-tests/helpers')
1314
const { withVersions } = require('../../../dd-trace/test/setup/mocha')
1415

@@ -42,7 +43,7 @@ describe('esm', () => {
4243
})
4344

4445
afterEach(async () => {
45-
proc?.kill()
46+
await stopProc(proc)
4647
await agent.stop()
4748
})
4849

packages/datadog-plugin-amqp10/test/integration-test/client.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
checkSpansForServiceName,
1010
spawnPluginIntegrationTestProcAndExpectExit,
1111
varySandbox,
12+
stopProc,
1213
} = require('../../../../integration-tests/helpers')
1314
const { withVersions } = require('../../../dd-trace/test/setup/mocha')
1415
describe('esm', () => {
@@ -29,7 +30,7 @@ describe('esm', () => {
2930
})
3031

3132
afterEach(async () => {
32-
proc && proc.kill()
33+
await stopProc(proc)
3334
await agent.stop()
3435
})
3536

packages/datadog-plugin-amqplib/test/integration-test/client.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
sandboxCwd,
1010
useSandbox,
1111
varySandbox,
12+
stopProc,
1213
} = require('../../../../integration-tests/helpers')
1314
const { withVersions } = require('../../../dd-trace/test/setup/mocha')
1415
describe('esm', () => {
@@ -30,7 +31,7 @@ describe('esm', () => {
3031
})
3132

3233
afterEach(async () => {
33-
proc && proc.kill()
34+
await stopProc(proc)
3435
await agent.stop()
3536
})
3637

packages/datadog-plugin-anthropic/test/integration-test/client.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const {
1010
checkSpansForServiceName,
1111
spawnPluginIntegrationTestProcAndExpectExit,
1212
varySandbox,
13+
stopProc,
1314
} = require('../../../../integration-tests/helpers')
1415
const { withVersions } = require('../../../dd-trace/test/setup/mocha')
1516

@@ -34,7 +35,7 @@ describe('esm', () => {
3435
})
3536

3637
afterEach(async () => {
37-
proc?.kill()
38+
await stopProc(proc)
3839
await agent.stop()
3940
})
4041

packages/datadog-plugin-aws-sdk/test/integration-test/client.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
checkSpansForServiceName,
1010
spawnPluginIntegrationTestProcAndExpectExit,
1111
varySandbox,
12+
stopProc,
1213
} = require('../../../../integration-tests/helpers')
1314
const { withVersions } = require('../../../dd-trace/test/setup/mocha')
1415
describe('esm', () => {
@@ -29,7 +30,7 @@ describe('esm', () => {
2930
})
3031

3132
afterEach(async () => {
32-
proc && proc.kill()
33+
await stopProc(proc)
3334
await agent.stop()
3435
})
3536

packages/datadog-plugin-aws-sdk/test/integration-test/sqs.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const {
77
useSandbox,
88
checkSpansForServiceName,
99
spawnPluginIntegrationTestProcAndExpectExit,
10+
stopProc,
1011
} = require('../../../../integration-tests/helpers')
1112
const { withVersions } = require('../../../dd-trace/test/setup/mocha')
1213

@@ -23,7 +24,7 @@ describe('recursion regression test', () => {
2324
})
2425

2526
afterEach(async () => {
26-
proc && proc.kill()
27+
await stopProc(proc)
2728
await agent.stop()
2829
})
2930

packages/datadog-plugin-axios/test/integration-test/client.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
checkSpansForServiceName,
1010
spawnPluginIntegrationTestProcAndExpectExit,
1111
varySandbox,
12+
stopProc,
1213
} = require('../../../../integration-tests/helpers')
1314
describe('esm', () => {
1415
let agent
@@ -27,7 +28,7 @@ describe('esm', () => {
2728
})
2829

2930
afterEach(async () => {
30-
proc && proc.kill()
31+
await stopProc(proc)
3132
await agent.stop()
3233
})
3334

packages/datadog-plugin-azure-durable-functions/test/integration-test/client.spec.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const {
1111
useSandbox,
1212
curlAndAssertMessage,
1313
assertObjectContains,
14+
stopProc,
1415
} = require('../../../../integration-tests/helpers')
1516
const { withVersions } = require('../../../dd-trace/test/setup/mocha')
1617

@@ -35,10 +36,7 @@ describe('esm', () => {
3536

3637
afterEach(async () => {
3738
// after each test, kill process and wait for exit before continuing
38-
if (proc) {
39-
proc.kill('SIGINT')
40-
await new Promise(resolve => proc.on('exit', resolve))
41-
}
39+
await stopProc(proc, { signal: 'SIGINT' })
4240
await agent.stop()
4341
})
4442

packages/datadog-plugin-azure-event-hubs/test/integration-test/batchSpanContextRegressionTest/client.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const {
66
sandboxCwd,
77
useSandbox,
88
spawnPluginIntegrationTestProcAndExpectExit,
9+
stopProc,
910
} = require('../../../../../integration-tests/helpers')
1011
const { withVersions } = require('../../../../dd-trace/test/setup/mocha')
1112

@@ -25,7 +26,7 @@ describe('esm', () => {
2526
})
2627

2728
afterEach(async () => {
28-
proc && proc.kill()
29+
await stopProc(proc)
2930
await agent.stop()
3031
})
3132

0 commit comments

Comments
 (0)