From 1c916e488f5ccd9decaf3d022640d22ca9ae5fea Mon Sep 17 00:00:00 2001 From: Rauno Viskus Date: Tue, 10 May 2022 13:43:33 +0300 Subject: [PATCH] feat: enable a way to disable amqp tests that require a server running (#1002) --- .github/workflows/unit-test.yml | 1 + .../test/amqplib-callbacks.test.ts | 22 +++++++++++++------ .../test/amqplib-connection.test.ts | 7 ++++++ .../test/amqplib-promise.test.ts | 13 ++++++++--- .../test/utils.test.ts | 13 ++++++++--- .../instrumentation-amqplib/test/utils.ts | 2 ++ 6 files changed, 45 insertions(+), 13 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 62ef100ed47..11a52e6df7f 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -98,6 +98,7 @@ jobs: RUN_MSSQL_TESTS: 1 RUN_POSTGRES_TESTS: 1 RUN_REDIS_TESTS: 1 + RUN_RABBIT_TESTS: 1 CASSANDRA_HOST: localhost MONGODB_DB: opentelemetry-tests MONGODB_HOST: 127.0.0.1 diff --git a/plugins/node/instrumentation-amqplib/test/amqplib-callbacks.test.ts b/plugins/node/instrumentation-amqplib/test/amqplib-callbacks.test.ts index 65973d5b1f1..424554e4dda 100644 --- a/plugins/node/instrumentation-amqplib/test/amqplib-callbacks.test.ts +++ b/plugins/node/instrumentation-amqplib/test/amqplib-callbacks.test.ts @@ -29,7 +29,7 @@ import { SemanticAttributes, } from '@opentelemetry/semantic-conventions'; import { context, SpanKind } from '@opentelemetry/api'; -import { asyncConfirmSend, asyncConsume } from './utils'; +import { asyncConfirmSend, asyncConsume, shouldTest } from './utils'; import { censoredUrl, rabbitMqUrl, @@ -42,14 +42,22 @@ const queueName = 'queue-name-from-unittest'; describe('amqplib instrumentation callback model', () => { let conn: amqpCallback.Connection; - before(done => { - amqpCallback.connect(rabbitMqUrl, (err, connection) => { - conn = connection; - done(err); - }); + before(function (done) { + if (!shouldTest) { + this.skip(); + } else { + amqpCallback.connect(rabbitMqUrl, (err, connection) => { + conn = connection; + done(err); + }); + } }); after(done => { - conn.close(() => done()); + if (!shouldTest) { + done(); + } else { + conn.close(() => done()); + } }); describe('channel', () => { diff --git a/plugins/node/instrumentation-amqplib/test/amqplib-connection.test.ts b/plugins/node/instrumentation-amqplib/test/amqplib-connection.test.ts index e80738e3102..748f06c7eed 100644 --- a/plugins/node/instrumentation-amqplib/test/amqplib-connection.test.ts +++ b/plugins/node/instrumentation-amqplib/test/amqplib-connection.test.ts @@ -15,6 +15,7 @@ */ import 'mocha'; import * as expect from 'expect'; +import { shouldTest } from './utils'; import { censoredUrl, rabbitMqUrl, @@ -34,6 +35,12 @@ import * as amqp from 'amqplib'; import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; describe('amqplib instrumentation connection', () => { + before(function () { + if (!shouldTest) { + this.skip(); + } + }); + describe('connect with url object', () => { it('should extract connection attributes form url options', async function () { const testName = this.test!.title; diff --git a/plugins/node/instrumentation-amqplib/test/amqplib-promise.test.ts b/plugins/node/instrumentation-amqplib/test/amqplib-promise.test.ts index 4863881739e..b343dc71ea2 100644 --- a/plugins/node/instrumentation-amqplib/test/amqplib-promise.test.ts +++ b/plugins/node/instrumentation-amqplib/test/amqplib-promise.test.ts @@ -41,6 +41,7 @@ import { } from '@opentelemetry/semantic-conventions'; import { Span, SpanKind, SpanStatusCode } from '@opentelemetry/api'; import { asyncConfirmPublish, asyncConfirmSend, asyncConsume } from './utils'; +import { shouldTest } from './utils'; import { censoredUrl, rabbitMqUrl, @@ -60,11 +61,17 @@ const CHANNEL_CLOSED_IN_TEST = Symbol( describe('amqplib instrumentation promise model', () => { let conn: amqp.Connection; - before(async () => { - conn = await amqp.connect(rabbitMqUrl); + before(async function () { + if (!shouldTest) { + this.skip(); + } else { + conn = await amqp.connect(rabbitMqUrl); + } }); after(async () => { - await conn.close(); + if (shouldTest) { + await conn.close(); + } }); let endHookSpy: SinonSpy; diff --git a/plugins/node/instrumentation-amqplib/test/utils.test.ts b/plugins/node/instrumentation-amqplib/test/utils.test.ts index 57cd59bb230..efa69b58866 100644 --- a/plugins/node/instrumentation-amqplib/test/utils.test.ts +++ b/plugins/node/instrumentation-amqplib/test/utils.test.ts @@ -21,16 +21,23 @@ import { } from '../src/utils'; import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; import * as amqp from 'amqplib'; +import { shouldTest } from './utils'; import { rabbitMqUrl } from './config'; describe('utils', () => { describe('getConnectionAttributesFromServer', () => { let conn: amqp.Connection; - before(async () => { - conn = await amqp.connect(rabbitMqUrl); + before(async function () { + if (!shouldTest) { + this.skip(); + } else { + conn = await amqp.connect(rabbitMqUrl); + } }); after(async () => { - await conn.close(); + if (shouldTest) { + await conn.close(); + } }); it('messaging system attribute', () => { diff --git a/plugins/node/instrumentation-amqplib/test/utils.ts b/plugins/node/instrumentation-amqplib/test/utils.ts index 42d68a7861e..f6297dfb662 100644 --- a/plugins/node/instrumentation-amqplib/test/utils.ts +++ b/plugins/node/instrumentation-amqplib/test/utils.ts @@ -100,3 +100,5 @@ export const asyncConsume = ( ) ); }; + +export const shouldTest = !!process.env.RUN_RABBIT_TESTS;