Skip to content

Commit d86c16b

Browse files
authored
chore(tests): added varySandbox for bullmq ESM tests (#7448)
Makes the ESM tests for bullmq comply with the current norms and verifies we properly instrument all esm exports.
1 parent c195ee8 commit d86c16b

File tree

5 files changed

+90
-64
lines changed

5 files changed

+90
-64
lines changed

packages/datadog-plugin-bullmq/test/integration-test/client.spec.js

Lines changed: 80 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ const {
88
useSandbox,
99
checkSpansForServiceName,
1010
spawnPluginIntegrationTestProcAndExpectExit,
11+
varySandbox,
1112
} = require('../../../../integration-tests/helpers')
1213
const { withVersions } = require('../../../dd-trace/test/setup/mocha')
1314

1415
describe('esm', () => {
1516
let agent
1617
let proc
18+
let variants
1719

1820
withVersions('bullmq', 'bullmq', '>=5.66.0', version => {
1921
useSandbox([`'bullmq@${version}'`], false, [
@@ -29,69 +31,93 @@ describe('esm', () => {
2931
})
3032

3133
describe('Queue.add()', () => {
32-
it('is instrumented', async () => {
33-
const res = agent.assertMessageReceived(({ headers, payload }) => {
34-
assert.strictEqual(headers.host, `127.0.0.1:${agent.port}`)
35-
assert.ok(Array.isArray(payload))
36-
assert.strictEqual(checkSpansForServiceName(payload, 'bullmq.add'), true)
37-
})
38-
39-
proc = await spawnPluginIntegrationTestProcAndExpectExit(sandboxCwd(), 'server-queue-add.mjs', agent.port)
40-
41-
await res
42-
}).timeout(60000)
34+
beforeEach(async () => {
35+
variants = varySandbox('server-queue-add.mjs', 'bullmq', 'Queue')
36+
})
37+
38+
for (const variant of varySandbox.VARIANTS) {
39+
it(`is instrumented ${variant}`, async () => {
40+
const res = agent.assertMessageReceived(({ headers, payload }) => {
41+
assert.strictEqual(headers.host, `127.0.0.1:${agent.port}`)
42+
assert.ok(Array.isArray(payload))
43+
assert.strictEqual(checkSpansForServiceName(payload, 'bullmq.add'), true)
44+
})
45+
46+
proc = await spawnPluginIntegrationTestProcAndExpectExit(sandboxCwd(), variants[variant], agent.port)
47+
48+
await res
49+
}).timeout(60000)
50+
}
4351
})
4452

4553
describe('Queue.addBulk()', () => {
46-
it('is instrumented', async () => {
47-
const res = agent.assertMessageReceived(({ headers, payload }) => {
48-
assert.strictEqual(headers.host, `127.0.0.1:${agent.port}`)
49-
assert.ok(Array.isArray(payload))
50-
assert.strictEqual(checkSpansForServiceName(payload, 'bullmq.addBulk'), true)
51-
})
52-
53-
proc = await spawnPluginIntegrationTestProcAndExpectExit(sandboxCwd(), 'server-queue-add-bulk.mjs', agent.port)
54-
55-
await res
56-
}).timeout(60000)
54+
beforeEach(async () => {
55+
variants = varySandbox('server-queue-add-bulk.mjs', 'bullmq', 'Queue')
56+
})
57+
58+
for (const variant of varySandbox.VARIANTS) {
59+
it(`is instrumented ${variant}`, async () => {
60+
const res = agent.assertMessageReceived(({ headers, payload }) => {
61+
assert.strictEqual(headers.host, `127.0.0.1:${agent.port}`)
62+
assert.ok(Array.isArray(payload))
63+
assert.strictEqual(checkSpansForServiceName(payload, 'bullmq.addBulk'), true)
64+
})
65+
66+
proc = await spawnPluginIntegrationTestProcAndExpectExit(sandboxCwd(), variants[variant], agent.port)
67+
68+
await res
69+
}).timeout(60000)
70+
}
5771
})
5872

5973
describe('FlowProducer.add()', () => {
60-
it('is instrumented', async () => {
61-
const res = agent.assertMessageReceived(({ headers, payload }) => {
62-
assert.strictEqual(headers.host, `127.0.0.1:${agent.port}`)
63-
assert.ok(Array.isArray(payload))
64-
assert.strictEqual(checkSpansForServiceName(payload, 'bullmq.add'), true)
65-
})
66-
67-
proc = await spawnPluginIntegrationTestProcAndExpectExit(
68-
sandboxCwd(),
69-
'server-flow-producer-add.mjs',
70-
agent.port
71-
)
72-
73-
await res
74-
}).timeout(60000)
74+
beforeEach(async () => {
75+
variants = varySandbox('server-flow-producer-add.mjs', 'bullmq', 'FlowProducer')
76+
})
77+
78+
for (const variant of varySandbox.VARIANTS) {
79+
it(`is instrumented ${variant}`, async () => {
80+
const res = agent.assertMessageReceived(({ headers, payload }) => {
81+
assert.strictEqual(headers.host, `127.0.0.1:${agent.port}`)
82+
assert.ok(Array.isArray(payload))
83+
assert.strictEqual(checkSpansForServiceName(payload, 'bullmq.add'), true)
84+
})
85+
86+
proc = await spawnPluginIntegrationTestProcAndExpectExit(
87+
sandboxCwd(),
88+
variants[variant],
89+
agent.port
90+
)
91+
92+
await res
93+
}).timeout(60000)
94+
}
7595
})
7696

7797
describe('Worker.callProcessJob()', () => {
78-
it('is instrumented', async () => {
79-
const res = agent.assertMessageReceived(({ headers, payload }) => {
80-
assert.strictEqual(headers.host, `127.0.0.1:${agent.port}`)
81-
assert.ok(Array.isArray(payload))
82-
assert.strictEqual(checkSpansForServiceName(payload, 'bullmq.processJob'), true)
83-
})
84-
85-
proc = await spawnPluginIntegrationTestProcAndExpectExit(
86-
sandboxCwd(),
87-
'server-worker-process-job.mjs',
88-
agent.port,
89-
// Disable Redis/ioredis instrumentation to avoid hitting max active requests limit
90-
{ DD_TRACE_REDIS_ENABLED: 'false', DD_TRACE_IOREDIS_ENABLED: 'false' }
91-
)
92-
93-
await res
94-
}).timeout(60000)
98+
beforeEach(async () => {
99+
variants = varySandbox('server-worker-process-job.mjs', 'bullmq', 'Queue, Worker, QueueEvents')
100+
})
101+
102+
for (const variant of varySandbox.VARIANTS) {
103+
it(`is instrumented ${variant}`, async () => {
104+
const res = agent.assertMessageReceived(({ headers, payload }) => {
105+
assert.strictEqual(headers.host, `127.0.0.1:${agent.port}`)
106+
assert.ok(Array.isArray(payload))
107+
assert.strictEqual(checkSpansForServiceName(payload, 'bullmq.processJob'), true)
108+
})
109+
110+
proc = await spawnPluginIntegrationTestProcAndExpectExit(
111+
sandboxCwd(),
112+
variants[variant],
113+
agent.port,
114+
// Disable Redis/ioredis instrumentation to avoid hitting max active requests limit
115+
{ DD_TRACE_REDIS_ENABLED: 'false', DD_TRACE_IOREDIS_ENABLED: 'false' }
116+
)
117+
118+
await res
119+
}).timeout(60000)
120+
}
95121
})
96122
})
97123
})

packages/datadog-plugin-bullmq/test/integration-test/server-flow-producer-add.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'dd-trace/init.js'
2-
import { FlowProducer } from 'bullmq'
2+
import bullmq from 'bullmq'
33

44
const connection = {
55
host: '127.0.0.1',
@@ -8,7 +8,7 @@ const connection = {
88

99
const queueName = 'esm-test-flow-producer'
1010

11-
const flowProducer = new FlowProducer({ connection })
11+
const flowProducer = new bullmq.FlowProducer({ connection })
1212

1313
// Test FlowProducer.add() - tests FlowProducer_add channel
1414
await flowProducer.add({

packages/datadog-plugin-bullmq/test/integration-test/server-queue-add-bulk.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'dd-trace/init.js'
2-
import { Queue } from 'bullmq'
2+
import bullmq from 'bullmq'
33

44
const connection = {
55
host: '127.0.0.1',
@@ -8,7 +8,7 @@ const connection = {
88

99
const queueName = 'esm-test-queue-add-bulk'
1010

11-
const queue = new Queue(queueName, { connection })
11+
const queue = new bullmq.Queue(queueName, { connection })
1212
await queue.waitUntilReady()
1313

1414
// Test Queue.addBulk() - tests Queue_addBulk channel

packages/datadog-plugin-bullmq/test/integration-test/server-queue-add.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'dd-trace/init.js'
2-
import { Queue } from 'bullmq'
2+
import bullmq from 'bullmq'
33

44
const connection = {
55
host: '127.0.0.1',
@@ -8,7 +8,7 @@ const connection = {
88

99
const queueName = 'esm-test-queue-add'
1010

11-
const queue = new Queue(queueName, { connection })
11+
const queue = new bullmq.Queue(queueName, { connection })
1212
await queue.waitUntilReady()
1313

1414
// Test Queue.add() - tests Queue_add channel

packages/datadog-plugin-bullmq/test/integration-test/server-worker-process-job.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'dd-trace/init.js'
2-
import { Queue, Worker, QueueEvents } from 'bullmq'
2+
import bullmq from 'bullmq'
33

44
const connection = {
55
host: '127.0.0.1',
@@ -10,16 +10,16 @@ const queueName = 'esm-test-worker-process'
1010

1111
// Create worker first and wait for it to be ready before creating the queue
1212
// This ensures the worker is listening before any jobs are added
13-
const worker = new Worker(queueName, async (job) => {
13+
const worker = new bullmq.Worker(queueName, async (job) => {
1414
return { processed: true, jobId: job.id }
1515
}, { connection })
1616

1717
await worker.waitUntilReady()
1818

19-
const queue = new Queue(queueName, { connection })
19+
const queue = new bullmq.Queue(queueName, { connection })
2020
await queue.waitUntilReady()
2121

22-
const queueEvents = new QueueEvents(queueName, { connection })
22+
const queueEvents = new bullmq.QueueEvents(queueName, { connection })
2323
await queueEvents.waitUntilReady()
2424

2525
// Add job and wait for processing to complete

0 commit comments

Comments
 (0)