3
3
require ( '../../setup/tap' )
4
4
5
5
const agent = require ( '../agent' )
6
- const getPort = require ( 'get-port' )
7
6
const { expect } = require ( 'chai' )
8
7
const axios = require ( 'axios' )
9
8
@@ -19,7 +18,6 @@ describe('Inferred Proxy Spans', function () {
19
18
process . env . DD_SERVICE = 'aws-server'
20
19
process . env . DD_TRACE_INFERRED_PROXY_SERVICES_ENABLED = 'true'
21
20
22
- port = await getPort ( )
23
21
require ( '../../../../dd-trace' )
24
22
25
23
await agent . load ( [ 'http' ] , null , options )
@@ -37,14 +35,19 @@ describe('Inferred Proxy Spans', function () {
37
35
}
38
36
} )
39
37
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
+ } )
41
44
}
42
45
43
46
// test cleanup function
44
- const cleanupTest = function ( ) {
47
+ const cleanupTest = async function ( ) {
45
48
appListener && appListener . close ( )
46
49
try {
47
- agent . close ( { ritmReset : false } )
50
+ await agent . close ( { ritmReset : false } )
48
51
} catch {
49
52
// pass
50
53
}
@@ -59,6 +62,8 @@ describe('Inferred Proxy Spans', function () {
59
62
'x-dd-proxy-stage' : 'dev'
60
63
}
61
64
65
+ afterEach ( cleanupTest )
66
+
62
67
describe ( 'without configuration' , ( ) => {
63
68
it ( 'should create a parent span and a child span for a 200' , async ( ) => {
64
69
await loadTest ( { } )
@@ -103,7 +108,7 @@ describe('Inferred Proxy Spans', function () {
103
108
continue
104
109
}
105
110
}
106
- } ) . then ( cleanupTest ) . catch ( cleanupTest )
111
+ } )
107
112
} )
108
113
109
114
it ( 'should create a parent span and a child span for an error' , async ( ) => {
@@ -150,7 +155,7 @@ describe('Inferred Proxy Spans', function () {
150
155
continue
151
156
}
152
157
}
153
- } ) . then ( cleanupTest ) . catch ( cleanupTest )
158
+ } )
154
159
} )
155
160
156
161
it ( 'should not create an API Gateway span if all necessary headers are missing' , async ( ) => {
@@ -182,7 +187,7 @@ describe('Inferred Proxy Spans', function () {
182
187
continue
183
188
}
184
189
}
185
- } ) . then ( cleanupTest ) . catch ( cleanupTest )
190
+ } )
186
191
} )
187
192
188
193
it ( 'should not create an API Gateway span if missing the proxy system header' , async ( ) => {
@@ -217,7 +222,7 @@ describe('Inferred Proxy Spans', function () {
217
222
continue
218
223
}
219
224
}
220
- } ) . then ( cleanupTest ) . catch ( cleanupTest )
225
+ } )
221
226
} )
222
227
} )
223
228
@@ -251,7 +256,7 @@ describe('Inferred Proxy Spans', function () {
251
256
continue
252
257
}
253
258
}
254
- } ) . then ( cleanupTest ) . catch ( cleanupTest )
259
+ } )
255
260
} )
256
261
} )
257
262
} )
0 commit comments