Skip to content

Commit f875381

Browse files
authored
test(integration): use stopProc helper for process teardown (#7661)
Replace direct proc.kill() in after/afterEach hooks with await stopProc(proc) so child processes are fully stopped before the next test runs, reducing flakiness from leaked state between tests.
1 parent c48215d commit f875381

21 files changed

+55
-46
lines changed

integration-tests/aiguard/index.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const path = require('path')
55

66
const { after, afterEach, before, beforeEach, describe, it } = require('mocha')
77

8-
const { sandboxCwd, useSandbox, FakeAgent, spawnProc } = require('../helpers')
8+
const { sandboxCwd, useSandbox, FakeAgent, spawnProc, stopProc } = require('../helpers')
99
const { assertObjectContains } = require('../helpers')
1010
const startApiMock = require('./api-mock')
1111
const { executeRequest } = require('./util')
@@ -44,7 +44,7 @@ describe('AIGuard SDK integration tests', () => {
4444
})
4545

4646
afterEach(async () => {
47-
proc.kill()
47+
await stopProc(proc)
4848
await agent.stop()
4949
})
5050

integration-tests/appsec/data-collection.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
useSandbox,
1010
FakeAgent,
1111
spawnProc,
12+
stopProc,
1213
} = require('../helpers')
1314

1415
describe('ASM Data collection', () => {
@@ -42,7 +43,7 @@ describe('ASM Data collection', () => {
4243
})
4344

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

integration-tests/appsec/endpoints-collection.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const path = require('node:path')
55

66
const { before, describe, it } = require('mocha')
77

8-
const { sandboxCwd, useSandbox, FakeAgent, spawnProc } = require('../helpers')
8+
const { sandboxCwd, useSandbox, FakeAgent, spawnProc, stopProc } = require('../helpers')
99

1010
describe('Endpoints collection', () => {
1111
let cwd
@@ -193,7 +193,7 @@ describe('Endpoints collection', () => {
193193
assert.strictEqual(invalidEndpoints.length, 0, 'Invalid router paths should not be collected')
194194
}
195195
} finally {
196-
proc?.kill()
196+
await stopProc(proc)
197197
await agent?.stop()
198198
}
199199
}

integration-tests/appsec/graphql.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
spawnProc,
12+
stopProc,
1213
} = require('../helpers')
1314

1415
describe('graphql', () => {
@@ -32,7 +33,7 @@ describe('graphql', () => {
3233
})
3334

3435
afterEach(async () => {
35-
proc.kill()
36+
await stopProc(proc)
3637
await agent.stop()
3738
})
3839

integration-tests/appsec/iast-esbuild.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const { promisify } = require('util')
1010
const Axios = require('axios')
1111
const msgpack = require('@msgpack/msgpack')
1212

13-
const { sandboxCwd, useSandbox, FakeAgent, spawnProc } = require('../helpers')
13+
const { sandboxCwd, useSandbox, FakeAgent, spawnProc, stopProc } = require('../helpers')
1414

1515
const exec = promisify(childProcess.exec)
1616
const retry = async fn => {
@@ -109,7 +109,7 @@ describe('esbuild support for IAST', () => {
109109
})
110110

111111
afterEach(async () => {
112-
contextVars.proc.kill()
112+
await stopProc(contextVars.proc)
113113
await contextVars.agent.stop()
114114
})
115115
}

integration-tests/appsec/iast-stack-traces-with-sourcemaps.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const assert = require('node:assert/strict')
55
const childProcess = require('child_process')
66
const path = require('path')
77
const Axios = require('axios')
8-
const { sandboxCwd, useSandbox, spawnProc, FakeAgent } = require('../helpers')
8+
const { sandboxCwd, useSandbox, spawnProc, FakeAgent, stopProc } = require('../helpers')
99
describe('IAST stack traces and vulnerabilities with sourcemaps', () => {
1010
let axios, cwd, appDir, appFile, agent, proc
1111

@@ -41,7 +41,7 @@ describe('IAST stack traces and vulnerabilities with sourcemaps', () => {
4141
})
4242

4343
afterEach(async () => {
44-
proc.kill()
44+
await stopProc(proc)
4545
await agent.stop()
4646
})
4747

integration-tests/appsec/iast.esm-security-controls.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const assert = require('node:assert/strict')
44

55
const path = require('path')
66
const Axios = require('axios')
7-
const { sandboxCwd, useSandbox, spawnProc, FakeAgent } = require('../helpers')
7+
const { sandboxCwd, useSandbox, spawnProc, FakeAgent, stopProc } = require('../helpers')
88
describe('ESM Security controls', () => {
99
let axios, cwd, appFile, agent, proc
1010

@@ -41,7 +41,7 @@ describe('ESM Security controls', () => {
4141
})
4242

4343
afterEach(async () => {
44-
proc.kill()
44+
await stopProc(proc)
4545
await agent.stop()
4646
})
4747

integration-tests/appsec/iast.esm.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const assert = require('node:assert/strict')
44

55
const path = require('path')
66
const Axios = require('axios')
7-
const { sandboxCwd, useSandbox, spawnProc, FakeAgent } = require('../helpers')
7+
const { sandboxCwd, useSandbox, spawnProc, FakeAgent, stopProc } = require('../helpers')
88
describe('ESM', () => {
99
let axios, cwd, appFile, agent, proc
1010

@@ -40,7 +40,7 @@ describe('ESM', () => {
4040
})
4141

4242
afterEach(async () => {
43-
proc.kill()
43+
await stopProc(proc)
4444
await agent.stop()
4545
})
4646

integration-tests/appsec/index.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const assert = require('node:assert/strict')
55
const path = require('path')
66
const Axios = require('axios')
77
const msgpack = require('@msgpack/msgpack')
8-
const { sandboxCwd, useSandbox, FakeAgent, spawnProc } = require('../helpers')
8+
const { sandboxCwd, useSandbox, FakeAgent, spawnProc, stopProc } = require('../helpers')
99

1010
describe('RASP', () => {
1111
let axios, cwd, appFile, agent, proc, stdioHandler
@@ -43,7 +43,7 @@ describe('RASP', () => {
4343
})
4444

4545
afterEach(async () => {
46-
proc.kill()
46+
await stopProc(proc)
4747
await agent.stop()
4848
})
4949
}

integration-tests/appsec/multer.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const {
1111
useSandbox,
1212
FakeAgent,
1313
spawnProc,
14+
stopProc,
1415
} = require('../helpers')
1516

1617
describe('multer', () => {
@@ -39,7 +40,7 @@ describe('multer', () => {
3940
})
4041

4142
afterEach(async () => {
42-
proc.kill()
43+
await stopProc(proc)
4344
await agent.stop()
4445
})
4546

0 commit comments

Comments
 (0)