Skip to content

Commit 5ac4852

Browse files
committed
add delayed route test
1 parent 635638d commit 5ac4852

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ describe('Endpoints collection', () => {
7373
{ method: 'GET', path: '/wildcard/*' },
7474
{ method: 'HEAD', path: '/wildcard/*' },
7575
{ method: 'GET', path: '*' },
76-
{ method: 'HEAD', path: '*' }
76+
{ method: 'HEAD', path: '*' },
77+
78+
{ method: 'GET', path: '/later' },
79+
{ method: 'HEAD', path: '/later' },
7780
]
7881

7982
return expectedEndpoints
@@ -85,20 +88,12 @@ describe('Endpoints collection', () => {
8588

8689
try {
8790
agent = await new FakeAgent().start()
88-
proc = await spawnProc(appFile, {
89-
cwd,
90-
env: {
91-
DD_TRACE_AGENT_PORT: agent.port,
92-
DD_TELEMETRY_HEARTBEAT_INTERVAL: 1,
93-
DD_API_SECURITY_ENDPOINT_COLLECTION_MESSAGE_LIMIT: '10'
94-
}
95-
})
9691

9792
const expectedEndpoints = getExpectedEndpoints(framework)
9893
const endpointsFound = []
9994
const isFirstFlags = []
10095

101-
await agent.assertTelemetryReceived(msg => {
96+
const telemetryPromise = agent.assertTelemetryReceived(msg => {
10297
const { payload } = msg
10398
if (payload.request_type === 'app-endpoints') {
10499
isFirstFlags.push(Boolean(payload.payload.is_first))
@@ -117,6 +112,17 @@ describe('Endpoints collection', () => {
117112
}
118113
}, 'app-endpoints', 5_000, 4)
119114

115+
proc = await spawnProc(appFile, {
116+
cwd,
117+
env: {
118+
DD_TRACE_AGENT_PORT: agent.port,
119+
DD_TELEMETRY_HEARTBEAT_INTERVAL: 1,
120+
DD_API_SECURITY_ENDPOINT_COLLECTION_MESSAGE_LIMIT: '10'
121+
}
122+
})
123+
124+
await telemetryPromise
125+
120126
const trueCount = isFirstFlags.filter(v => v === true).length
121127
expect(trueCount).to.equal(1)
122128

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,7 @@ const start = async () => {
6161
process.send({ port })
6262
}
6363

64-
start()
64+
setTimeout(() => {
65+
app.get('/later', async (_, reply) => reply.send('ok'))
66+
start()
67+
}, 2e3)

0 commit comments

Comments
 (0)