Skip to content

Commit 8dd1be7

Browse files
committed
trying to fix test race condition
1 parent 5cd400b commit 8dd1be7

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

packages/datadog-plugin-undici/test/index.spec.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ describe('Plugin', () => {
2626
}
2727

2828
beforeEach(() => {
29+
console.log('BE')
2930
appListener = null
3031
})
3132

3233
afterEach(() => {
34+
console.log('AE')
3335
if (appListener) {
3436
appListener.close()
3537
}
@@ -38,10 +40,12 @@ describe('Plugin', () => {
3840

3941
describe('without configuration', () => {
4042
beforeEach(async () => {
43+
console.log('BEE')
4144
return await agent.load('undici', {
4245
service: 'test'
4346
})
4447
.then(() => {
48+
console.log('BEEX')
4549
express = require('express')
4650
fetch = require('undici')
4751
})
@@ -68,8 +72,10 @@ describe('Plugin', () => {
6872
res.status(200).send()
6973
})
7074
getPort().then(port => {
71-
agent
75+
console.log('GOT A PORT', port)
76+
const p = agent
7277
.use(traces => {
78+
console.log('AGENT USING TRACE')
7379
expect(traces[0][0]).to.have.property('service', 'test')
7480
expect(traces[0][0]).to.have.property('type', 'http')
7581
expect(traces[0][0]).to.have.property('resource', 'GET')
@@ -79,12 +85,19 @@ describe('Plugin', () => {
7985
expect(traces[0][0].meta).to.have.property('http.status_code', '200')
8086
expect(traces[0][0].meta).to.have.property('component', 'undici')
8187
expect(traces[0][0].meta).to.have.property('out.host', 'localhost')
88+
done()
8289
})
8390

8491
appListener = server(app, port, () => {
85-
fetch.fetch(`http://localhost:${port}/user`, { method: 'GET' })
92+
console.log('SERVER READY')
93+
setTimeout(() => {
94+
console.log('DELAY FETCH')
95+
fetch.fetch(`http://localhost:${port}/user`, { method: 'GET' })
96+
}, 100)
8697
})
87-
setTimeout(done, 100)
98+
99+
console.log('RETURNING')
100+
return p
88101
})
89102
})
90103
it('should support URL input', done => {

0 commit comments

Comments
 (0)