Skip to content

Commit 5d7a7f1

Browse files
authored
Fix overhead controller test flakyness (#5824)
1 parent f099f66 commit 5d7a7f1

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

packages/dd-trace/test/appsec/iast/overhead-controller.spec.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,6 @@ describe('Overhead controller', () => {
411411

412412
function tests (serverConfig) {
413413
const handlers = []
414-
415414
beforeEach(() => {
416415
testRequestEventEmitter
417416
.removeAllListeners(TEST_REQUEST_STARTED)
@@ -583,29 +582,27 @@ describe('Overhead controller', () => {
583582
}
584583
handlers.push(handler)
585584
agent.subscribe(handler)
586-
587585
testRequestEventEmitter.on(TEST_REQUEST_STARTED, (url) => {
588586
if (url === FIRST_REQUEST) {
589587
axios.get(`http://localhost:${serverConfig.port}${SECOND_REQUEST}`).then().catch(done)
590588
} else if (url === SECOND_REQUEST) {
591589
axios.get(`http://localhost:${serverConfig.port}${THIRD_REQUEST}`).then().catch(done)
592590
} else if (url === THIRD_REQUEST) {
593591
requestResolvers[FIRST_REQUEST]()
592+
} else if (url === FOURTH_REQUEST) {
593+
axios.get(`http://localhost:${serverConfig.port}${FIFTH_REQUEST}`).then().catch(done)
594594
} else if (url === FIFTH_REQUEST) {
595595
requestResolvers[SECOND_REQUEST]()
596596
}
597597
})
598+
598599
testRequestEventEmitter.on(TEST_REQUEST_FINISHED, (url) => {
599600
if (url === FIRST_REQUEST) {
600601
axios.get(`http://localhost:${serverConfig.port}${FOURTH_REQUEST}`).then().catch(done)
601-
axios.get(`http://localhost:${serverConfig.port}${FIFTH_REQUEST}`).then().catch(done)
602602
} else if (url === SECOND_REQUEST) {
603-
// Previously this was a setImmediate, but that made this flaky. Waiting 100ms de-flakes it.
604-
setTimeout(() => {
605-
requestResolvers[THIRD_REQUEST]()
606-
requestResolvers[FOURTH_REQUEST]()
607-
requestResolvers[FIFTH_REQUEST]()
608-
}, 100)
603+
requestResolvers[THIRD_REQUEST]()
604+
requestResolvers[FOURTH_REQUEST]()
605+
requestResolvers[FIFTH_REQUEST]()
609606
}
610607
})
611608

packages/dd-trace/test/appsec/iast/utils.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ function testInRequest (app, tests) {
2121
let appListener
2222
const config = {}
2323

24+
before(() => {
25+
return agent.load('http', undefined, { flushInterval: 1 })
26+
.then(() => {
27+
http = require('http')
28+
})
29+
})
30+
2431
beforeEach(() => {
2532
listener = (req, res) => {
2633
const appResult = app && app(req, res)
@@ -36,13 +43,6 @@ function testInRequest (app, tests) {
3643
}
3744
})
3845

39-
beforeEach(() => {
40-
return agent.load('http', undefined, { flushInterval: 1 })
41-
.then(() => {
42-
http = require('http')
43-
})
44-
})
45-
4646
beforeEach(done => {
4747
const server = new http.Server(listener)
4848
appListener = server
@@ -54,6 +54,9 @@ function testInRequest (app, tests) {
5454

5555
afterEach(() => {
5656
appListener && appListener.close()
57+
})
58+
59+
after(() => {
5760
return agent.close({ ritmReset: false })
5861
})
5962

0 commit comments

Comments
 (0)