Skip to content

Commit af26294

Browse files
committed
test(node-integration): Give each amqplib run its own queue
The queues are exclusive, and the broker can still hold the lock of the previous run when the next run declares the same queue name (RESOURCE-LOCKED). The broker now names the queue of the topic scenario, and the callback scenario gets a unique name from the test.
1 parent 56db855 commit af26294

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

‎dev-packages/node-integration-tests/suites/tracing/amqplib/scenario-callback-api.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as Sentry from '@sentry/node';
22
import amqp from 'amqplib/callback_api.js';
33

4-
const queueName = 'callback-queue';
4+
const queueName = process.env.AMQP_QUEUE_NAME;
55
const amqpUsername = 'sentry';
66
const amqpPassword = 'sentry';
77

‎dev-packages/node-integration-tests/suites/tracing/amqplib/scenario-topic-noack.mjs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import amqp from 'amqplib';
33

44
// A topic exchange, so the routing key and the queue name differ.
55
const exchangeName = 'orders';
6-
const queueName = 'orders-worker';
76
const routingKey = 'order.created.12345';
87
const amqpUsername = 'sentry';
98
const amqpPassword = 'sentry';
@@ -16,8 +15,12 @@ const NO_ACKNOWLEDGEMENT = { noAck: true };
1615
(async () => {
1716
const { connection, channel } = await connectToRabbitMQ();
1817

19-
await channel.assertExchange(exchangeName, 'topic', { durable: false, autoDelete: true });
20-
await channel.assertQueue(queueName, { durable: false, exclusive: true });
18+
// The ESM and CJS runs of all versions share the exchange, so it must not go away with the queue
19+
// of an earlier run.
20+
await channel.assertExchange(exchangeName, 'topic', { durable: false });
21+
// An exclusive queue stays locked until the broker has cleaned up its connection, which can be
22+
// after the next run starts. The broker names the queue, so no two runs share one.
23+
const { queue: queueName } = await channel.assertQueue('', { durable: false, exclusive: true });
2124
await channel.bindQueue(queueName, exchangeName, 'order.created.#');
2225

2326
// Publish before consuming, so the broker sends `BasicConsumeOk` and the delivery back to back.

‎dev-packages/node-integration-tests/suites/tracing/amqplib/test.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
URL_FULL,
1515
} from '@sentry/conventions/attributes';
1616
import { QUEUE_PROCESS, QUEUE_PUBLISH } from '@sentry/conventions/op';
17+
import { randomUUID } from 'crypto';
1718
import { afterAll, describe, expect } from 'vitest';
1819
import { cleanupChildProcesses, createEsmAndCjsTests, describeWithDockerCompose } from '../../../utils/runner';
1920

@@ -201,18 +202,22 @@ describeWithDockerCompose('amqplib auto-instrumentation', { workingDirectory: [_
201202

202203
createEsmAndCjsTests(__dirname, 'scenario-callback-api.mjs', 'instrument.mjs', (createTestRunner, test) => {
203204
test('instruments publish and noAck consume on the callback API', { timeout: 60_000 }, async () => {
205+
// The queue is exclusive, and the broker can still hold the lock of the previous run.
206+
const queueName = `callback-queue-${randomUUID()}`;
207+
204208
await createTestRunner()
209+
.withEnv({ AMQP_QUEUE_NAME: queueName })
205210
.expect({
206211
span: container => {
207212
const producerSpan = container.items.find(
208213
span => span.attributes[SENTRY_ORIGIN]?.value === 'auto.queue.amqplib.publisher',
209214
);
210-
expect(producerSpan?.name).toBe('send callback-queue');
215+
expect(producerSpan?.name).toBe(`send ${queueName}`);
211216

212217
const consumerSpan = container.items.find(
213218
span => span.attributes[SENTRY_ORIGIN]?.value === 'auto.queue.amqplib.consumer',
214219
);
215-
expect(consumerSpan?.name).toBe('process callback-queue');
220+
expect(consumerSpan?.name).toBe(`process ${queueName}`);
216221
expect(consumerSpan?.status).toBe('ok');
217222
},
218223
})

0 commit comments

Comments
 (0)