Skip to content

Commit e87a8ca

Browse files
committed
fix sqs test race condition when deleting the queue (#6068)
1 parent dae58ff commit e87a8ca

File tree

10 files changed

+75
-53
lines changed

10 files changed

+75
-53
lines changed

packages/datadog-plugin-aws-sdk/test/sqs.spec.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,36 +99,38 @@ describe('Plugin', () => {
9999
)
100100

101101
withNamingSchema(
102-
(done) => sqs.sendMessage({
102+
() => new Promise((resolve, reject) => sqs.sendMessage({
103103
MessageBody: 'test body',
104104
QueueUrl
105-
}, (err) => err && done(err)),
105+
}, (err) => err ? reject(err) : resolve())),
106106
rawExpectedSchema.producer,
107107
{
108108
desc: 'producer'
109109
}
110110
)
111111

112112
withNamingSchema(
113-
(done) => sqs.sendMessage({
113+
() => new Promise((resolve, reject) => sqs.sendMessage({
114114
MessageBody: 'test body',
115115
QueueUrl
116116
}, (err) => {
117-
if (err) return done(err)
117+
if (err) return reject(err)
118118

119119
sqs.receiveMessage({
120120
QueueUrl,
121121
MessageAttributeNames: ['.*']
122-
}, (err) => err && done(err))
123-
}),
122+
}, (err) => err ? reject(err) : resolve())
123+
})),
124124
rawExpectedSchema.consumer,
125125
{
126126
desc: 'consumer'
127127
}
128128
)
129129

130130
withNamingSchema(
131-
(done) => sqs.listQueues({}, (err) => err && done(err)),
131+
() => new Promise((resolve, reject) => {
132+
sqs.listQueues({}, (err) => err ? reject(err) : resolve())
133+
}),
132134
rawExpectedSchema.client,
133135
{
134136
desc: 'client'

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,17 @@ describe('Plugin', () => {
304304
client.ping().catch(done)
305305
})
306306

307-
withNamingSchema(
308-
() => client.search(
309-
{ index: 'logstash-2000.01.01', body: {} },
310-
hasCallbackSupport ? () => {} : undefined
311-
),
312-
rawExpectedSchema.outbound
313-
)
307+
describe('test', () => {
308+
withNamingSchema(
309+
() => {
310+
client.search(
311+
{ index: 'logstash-2000.01.01', body: {} },
312+
hasCallbackSupport ? () => {} : undefined
313+
)
314+
},
315+
rawExpectedSchema.outbound
316+
)
317+
})
314318
})
315319
})
316320

@@ -370,10 +374,12 @@ describe('Plugin', () => {
370374
})
371375

372376
withNamingSchema(
373-
() => client.search(
374-
{ index: 'logstash-2000.01.01', body: {} },
375-
hasCallbackSupport ? () => {} : undefined
376-
),
377+
() => {
378+
client.search(
379+
{ index: 'logstash-2000.01.01', body: {} },
380+
hasCallbackSupport ? () => {} : undefined
381+
)
382+
},
377383
{
378384
v0: {
379385
opName: 'elasticsearch.query',
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'dd-trace/init.js'
22
import { Client } from '@elastic/elasticsearch'
33

4-
const client = new Client({ node: 'http://localhost:9200' })
4+
const client = new Client({ node: 'http://127.0.0.1:9200' })
55

66
await client.ping()

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('Plugin', () => {
3434
mysql2 = proxyquire(`../../../versions/mysql2@${version}`, {}).get()
3535

3636
connection = mysql2.createConnection({
37-
host: 'localhost',
37+
host: '127.0.0.1',
3838
user: 'root',
3939
database: 'db'
4040
})
@@ -51,7 +51,9 @@ describe('Plugin', () => {
5151
)
5252

5353
withNamingSchema(
54-
() => connection.query('SELECT 1', (_) => {}),
54+
() => new Promise((resolve) => {
55+
connection.query('SELECT 1', (_) => resolve())
56+
}),
5557
rawExpectedSchema.outbound
5658
)
5759

@@ -213,7 +215,7 @@ describe('Plugin', () => {
213215
mysql2 = proxyquire(`../../../versions/mysql2@${version}`, {}).get()
214216

215217
connection = mysql2.createConnection({
216-
host: 'localhost',
218+
host: '127.0.0.1',
217219
user: 'root',
218220
database: 'db'
219221
})
@@ -222,7 +224,9 @@ describe('Plugin', () => {
222224
})
223225

224226
withNamingSchema(
225-
() => connection.query('SELECT 1', (_) => {}),
227+
() => new Promise((resolve) => {
228+
connection.query('SELECT 1', (_) => resolve())
229+
}),
226230
{
227231
v0: {
228232
opName: 'mysql.query',
@@ -262,7 +266,7 @@ describe('Plugin', () => {
262266
mysql2 = proxyquire(`../../../versions/mysql2@${version}`, {}).get()
263267

264268
connection = mysql2.createConnection({
265-
host: 'localhost',
269+
host: '127.0.0.1',
266270
user: 'root',
267271
database: 'db'
268272
})
@@ -271,7 +275,9 @@ describe('Plugin', () => {
271275
})
272276

273277
withNamingSchema(
274-
() => connection.query('SELECT 1', (_) => {}),
278+
() => new Promise((resolve) => {
279+
connection.query('SELECT 1', (_) => resolve())
280+
}),
275281
{
276282
v0: {
277283
opName: 'mysql.query',
@@ -288,7 +294,7 @@ describe('Plugin', () => {
288294
agent.assertSomeTraces(traces => {
289295
expect(traces[0][0]).to.have.property('service', 'custom')
290296
sinon.assert.calledWith(serviceSpy, sinon.match({
291-
host: 'localhost',
297+
host: '127.0.0.1',
292298
user: 'root',
293299
database: 'db'
294300
}))
@@ -314,7 +320,7 @@ describe('Plugin', () => {
314320

315321
pool = mysql2.createPool({
316322
connectionLimit: 1,
317-
host: 'localhost',
323+
host: '127.0.0.1',
318324
user: 'root'
319325
})
320326
})

packages/datadog-plugin-mysql2/test/integration-test/server.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'dd-trace/init.js'
22
import mysql from 'mysql2'
33

44
const conn = {
5-
host: 'localhost',
5+
host: '127.0.0.1',
66
user: 'root',
77
database: 'db',
88
port: 3306

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('Plugin', () => {
3333
opensearch = metaModule.get()
3434

3535
client = new opensearch.Client({
36-
node: 'http://localhost:9201'
36+
node: 'http://127.0.0.1:9201'
3737
})
3838
})
3939

@@ -67,7 +67,7 @@ describe('Plugin', () => {
6767
'opensearch.url': '/docs/_search',
6868
'opensearch.body': '{"query":{"match_all":{}}}',
6969
component: 'opensearch',
70-
'out.host': 'localhost'
70+
'out.host': '127.0.0.1'
7171
}
7272
})
7373
.then(done)
@@ -213,7 +213,9 @@ describe('Plugin', () => {
213213
})
214214

215215
withNamingSchema(
216-
() => client.search({ index: 'logstash-2000.01.01', body: {} }),
216+
() => {
217+
client.search({ index: 'logstash-2000.01.01', body: {} })
218+
},
217219
rawExpectedSchema.outbound
218220
)
219221
})
@@ -239,7 +241,7 @@ describe('Plugin', () => {
239241
beforeEach(() => {
240242
opensearch = require(`../../../versions/${moduleName}@${version}`).get()
241243
client = new opensearch.Client({
242-
node: 'http://localhost:9201'
244+
node: 'http://127.0.0.1:9201'
243245
})
244246
})
245247

@@ -258,7 +260,7 @@ describe('Plugin', () => {
258260
}).catch(() => {
259261
// Ignore index_not_found_exception for peer service assertion
260262
}),
261-
'localhost',
263+
'127.0.0.1',
262264
'out.host'
263265
)
264266

@@ -291,7 +293,9 @@ describe('Plugin', () => {
291293
})
292294

293295
withNamingSchema(
294-
() => client.search({ index: 'logstash-2000.01.01', body: {} }),
296+
() => {
297+
client.search({ index: 'logstash-2000.01.01', body: {} })
298+
},
295299
{
296300
v0: {
297301
opName: 'opensearch.query',
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'dd-trace/init.js'
22
import opensearch from '@opensearch-project/opensearch'
33

4-
const client = new opensearch.Client({ node: 'http://localhost:9201' })
4+
const client = new opensearch.Client({ node: 'http://127.0.0.1:9201' })
55
await client.ping()

packages/dd-trace/test/setup/mocha.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ function withNamingSchema (
6262

6363
it('should conform to the naming schema', function () {
6464
this.timeout(10000)
65+
6566
return new Promise((resolve, reject) => {
66-
agent
67+
const agentPromise = agent
6768
.assertSomeTraces(traces => {
6869
const span = selectSpan(traces)
6970
const expectedOpName = typeof opName === 'function'
@@ -76,9 +77,10 @@ function withNamingSchema (
7677
expect(span).to.have.property('name', expectedOpName)
7778
expect(span).to.have.property('service', expectedServiceName)
7879
})
79-
.then(resolve)
80-
.catch(reject)
81-
spanProducerFn(reject)
80+
81+
const testPromise = spanProducerFn(reject)
82+
83+
Promise.all([testPromise, agentPromise]).then(resolve, reject)
8284
})
8385
})
8486
})
@@ -102,19 +104,21 @@ function withNamingSchema (
102104

103105
const { serviceName } = expected.v1
104106

105-
it('should pass service name through', done => {
106-
agent
107-
.assertSomeTraces(traces => {
108-
const span = traces[0][0]
109-
const expectedServiceName = typeof serviceName === 'function'
110-
? serviceName()
111-
: serviceName
112-
expect(span).to.have.property('service', expectedServiceName)
113-
})
114-
.then(done)
115-
.catch(done)
107+
it('should pass service name through', () => {
108+
return new Promise((resolve, reject) => {
109+
const agentPromise = agent
110+
.assertSomeTraces(traces => {
111+
const span = traces[0][0]
112+
const expectedServiceName = typeof serviceName === 'function'
113+
? serviceName()
114+
: serviceName
115+
expect(span).to.have.property('service', expectedServiceName)
116+
})
117+
118+
const testPromise = spanProducerFn(reject)
116119

117-
spanProducerFn(done)
120+
Promise.all([testPromise, agentPromise]).then(resolve, reject)
121+
})
118122
})
119123
})
120124
})

packages/dd-trace/test/setup/services/elasticsearch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function waitForElasticsearch () {
99

1010
operation.attempt(currentAttempt => {
1111
// Not using ES client because it's buggy for initial connection.
12-
axios.get('http://localhost:9200/_cluster/health?wait_for_status=green&local=true&timeout=100ms')
12+
axios.get('http://127.0.0.1:9200/_cluster/health?wait_for_status=green&local=true&timeout=100ms')
1313
.then(() => resolve())
1414
.catch(err => {
1515
if (operation.retry(err)) return

packages/dd-trace/test/setup/services/mysql.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function waitForMysql () {
99

1010
operation.attempt(currentAttempt => {
1111
const connection = mysql.createConnection({
12-
host: 'localhost',
12+
host: '127.0.0.1',
1313
user: 'root',
1414
database: 'db'
1515
})

0 commit comments

Comments
 (0)