From 621c165ebcb0d1a946bd599afd85488333ddc39b Mon Sep 17 00:00:00 2001 From: Francesco Gringl-Novy Date: Mon, 15 Jun 2026 14:48:19 +0200 Subject: [PATCH] test(node): Make amqplib integration test order-independent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `amqplib auto-instrumentation` test (`suites/tracing/amqplib/test.ts`) asserted the producer (`root span`) and consumer (`queue1 process`) transactions in a fixed order via two sequential `.expect()` callbacks. The runner matches expected envelopes strictly FIFO, but the producer and consumer are independent traces flushed independently, so their arrival order is not guaranteed — when the consumer envelope arrived first, the producer assertion failed against it. Apply the same collect-then-assert fix already used for the `amqplib-v1` test (#21534) and `kafkajs`: collect both transactions, then look them up by name and assert once both have arrived. All original assertions are preserved. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../suites/tracing/amqplib/test.ts | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/dev-packages/node-integration-tests/suites/tracing/amqplib/test.ts b/dev-packages/node-integration-tests/suites/tracing/amqplib/test.ts index 62f2931daba5..8e7ce3358ddb 100644 --- a/dev-packages/node-integration-tests/suites/tracing/amqplib/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/amqplib/test.ts @@ -31,21 +31,33 @@ describe('amqplib auto-instrumentation', () => { createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createTestRunner, test) => { test('should be able to send and receive messages', { timeout: 60_000 }, async () => { + // The producer ('root span') and consumer ('queue1 process') transactions can + // arrive in any order, so we collect them and assert after both are received. + const receivedTransactions: TransactionEvent[] = []; + await createTestRunner() .withDockerCompose({ workingDirectory: [__dirname], }) .expect({ transaction: (transaction: TransactionEvent) => { - expect(transaction.transaction).toEqual('root span'); - expect(transaction.spans?.length).toEqual(1); - expect(transaction.spans![0]).toMatchObject(EXPECTED_MESSAGE_SPAN_PRODUCER); + receivedTransactions.push(transaction); }, }) .expect({ transaction: (transaction: TransactionEvent) => { - expect(transaction.transaction).toEqual('queue1 process'); - expect(transaction.contexts?.trace).toMatchObject(EXPECTED_MESSAGE_SPAN_CONSUMER); + receivedTransactions.push(transaction); + + const producer = receivedTransactions.find(t => t.transaction === 'root span'); + const consumer = receivedTransactions.find(t => t.transaction === 'queue1 process'); + + expect(producer).toBeDefined(); + expect(consumer).toBeDefined(); + + expect(producer!.spans?.length).toEqual(1); + expect(producer!.spans![0]).toMatchObject(EXPECTED_MESSAGE_SPAN_PRODUCER); + + expect(consumer!.contexts?.trace).toMatchObject(EXPECTED_MESSAGE_SPAN_CONSUMER); }, }) .start()