Skip to content

Commit 86327a4

Browse files
[test optimization] Improve afterEach in cypress integration tests (#6491)
1 parent 3f33a1e commit 86327a4

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

integration-tests/cypress/cypress.spec.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const { DD_HOST_CPU_COUNT } = require('../../packages/dd-trace/src/plugins/util/
6565
const { ERROR_MESSAGE } = require('../../packages/dd-trace/src/constants')
6666
const { DD_MAJOR, NODE_MAJOR } = require('../../version')
6767

68+
const RECEIVER_STOP_TIMEOUT = 20000
6869
const version = process.env.CYPRESS_VERSION
6970
const hookFile = 'dd-trace/loader-hook.mjs'
7071
const NUM_RETRIES_EFD = 3
@@ -154,9 +155,24 @@ moduleTypes.forEach(({
154155
receiver = await new FakeCiVisIntake().start()
155156
})
156157

158+
// Cypress child processes can sometimes hang or take longer to
159+
// terminate. This can cause `FakeCiVisIntake#stop` to be delayed
160+
// because there are pending connections.
157161
afterEach(async () => {
158162
childProcess.kill()
159-
await receiver.stop()
163+
164+
// Add timeout to prevent hanging
165+
const stopPromise = receiver.stop()
166+
const timeoutPromise = new Promise((resolve, reject) =>
167+
setTimeout(() => reject(new Error('Receiver stop timeout')), RECEIVER_STOP_TIMEOUT)
168+
)
169+
170+
try {
171+
await Promise.race([stopPromise, timeoutPromise])
172+
} catch (error) {
173+
// eslint-disable-next-line no-console
174+
console.warn('Receiver stop timed out:', error.message)
175+
}
160176
})
161177

162178
if (version === '6.7.0') {

0 commit comments

Comments
 (0)