Skip to content

Commit 5822d12

Browse files
authored
fix(test): Fix flaky amqplib test (#13860)
Managed to stop flakes locally with these updates
1 parent d891e06 commit 5822d12

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

dev-packages/node-integration-tests/suites/tracing/amqplib/scenario-message.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@ import { connectToRabbitMQ, consumeMessageFromQueue, createQueue, sendMessageToQ
44

55
const queueName = 'queue1';
66

7+
// Stop the process from exiting before the transaction is sent
8+
// eslint-disable-next-line @typescript-eslint/no-empty-function
9+
setInterval(() => {}, 1000);
10+
711
// eslint-disable-next-line @typescript-eslint/no-floating-promises
812
(async () => {
913
const { connection, channel } = await connectToRabbitMQ();
1014
await createQueue(queueName, channel);
1115

16+
const consumeMessagePromise = consumeMessageFromQueue(queueName, channel);
17+
1218
await Sentry.startSpan({ name: 'root span' }, async () => {
1319
sendMessageToQueue(queueName, channel, JSON.stringify({ foo: 'bar01' }));
1420
});
1521

16-
await consumeMessageFromQueue(queueName, channel);
22+
await consumeMessagePromise;
23+
1724
await channel.close();
1825
await connection.close();
1926
})();

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,22 @@ export function sendMessageToQueue(queueName: string, channel: Channel, message:
2222
}
2323

2424
async function consumer(queueName: string, channel: Channel): Promise<void> {
25-
await channel.consume(
26-
queueName,
27-
message => {
28-
if (message) {
29-
channel.ack(message);
30-
}
31-
},
32-
ACKNOWLEDGEMENT,
33-
);
25+
return new Promise((resolve, reject) => {
26+
channel
27+
.consume(
28+
queueName,
29+
message => {
30+
if (message) {
31+
channel.ack(message);
32+
resolve();
33+
} else {
34+
reject(new Error('No message received'));
35+
}
36+
},
37+
ACKNOWLEDGEMENT,
38+
)
39+
.catch(reject);
40+
});
3441
}
3542

3643
export async function consumeMessageFromQueue(queueName: string, channel: Channel): Promise<void> {

0 commit comments

Comments
 (0)