Skip to content

Commit b4edcab

Browse files
authored
test: remove get-port usage from inferred proxy test (#6054)
* move test cleanup to hook
1 parent f2f650b commit b4edcab

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

packages/dd-trace/test/plugins/util/inferred_proxy.spec.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require('../../setup/tap')
44

55
const agent = require('../agent')
6-
const getPort = require('get-port')
76
const { expect } = require('chai')
87
const axios = require('axios')
98

@@ -19,7 +18,6 @@ describe('Inferred Proxy Spans', function () {
1918
process.env.DD_SERVICE = 'aws-server'
2019
process.env.DD_TRACE_INFERRED_PROXY_SERVICES_ENABLED = 'true'
2120

22-
port = await getPort()
2321
require('../../../../dd-trace')
2422

2523
await agent.load(['http'], null, options)
@@ -37,14 +35,19 @@ describe('Inferred Proxy Spans', function () {
3735
}
3836
})
3937

40-
appListener = server.listen(port, '127.0.0.1')
38+
return new Promise((resolve, reject) => {
39+
appListener = server.listen(0, '127.0.0.1', () => {
40+
port = server.address().port
41+
resolve()
42+
})
43+
})
4144
}
4245

4346
// test cleanup function
44-
const cleanupTest = function () {
47+
const cleanupTest = async function () {
4548
appListener && appListener.close()
4649
try {
47-
agent.close({ ritmReset: false })
50+
await agent.close({ ritmReset: false })
4851
} catch {
4952
// pass
5053
}
@@ -59,6 +62,8 @@ describe('Inferred Proxy Spans', function () {
5962
'x-dd-proxy-stage': 'dev'
6063
}
6164

65+
afterEach(cleanupTest)
66+
6267
describe('without configuration', () => {
6368
it('should create a parent span and a child span for a 200', async () => {
6469
await loadTest({})
@@ -103,7 +108,7 @@ describe('Inferred Proxy Spans', function () {
103108
continue
104109
}
105110
}
106-
}).then(cleanupTest).catch(cleanupTest)
111+
})
107112
})
108113

109114
it('should create a parent span and a child span for an error', async () => {
@@ -150,7 +155,7 @@ describe('Inferred Proxy Spans', function () {
150155
continue
151156
}
152157
}
153-
}).then(cleanupTest).catch(cleanupTest)
158+
})
154159
})
155160

156161
it('should not create an API Gateway span if all necessary headers are missing', async () => {
@@ -182,7 +187,7 @@ describe('Inferred Proxy Spans', function () {
182187
continue
183188
}
184189
}
185-
}).then(cleanupTest).catch(cleanupTest)
190+
})
186191
})
187192

188193
it('should not create an API Gateway span if missing the proxy system header', async () => {
@@ -217,7 +222,7 @@ describe('Inferred Proxy Spans', function () {
217222
continue
218223
}
219224
}
220-
}).then(cleanupTest).catch(cleanupTest)
225+
})
221226
})
222227
})
223228

@@ -251,7 +256,7 @@ describe('Inferred Proxy Spans', function () {
251256
continue
252257
}
253258
}
254-
}).then(cleanupTest).catch(cleanupTest)
259+
})
255260
})
256261
})
257262
})

0 commit comments

Comments
 (0)