Skip to content

Commit

Permalink
feat: enable a way to disable amqp tests that require a server running (
Browse files Browse the repository at this point in the history
  • Loading branch information
rauno56 authored May 10, 2022
1 parent 0293d89 commit 1c916e4
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 13 deletions.
1 change: 1 addition & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
import 'mocha';
import * as expect from 'expect';
import { shouldTest } from './utils';
import {
censoredUrl,
rabbitMqUrl,
Expand All @@ -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;
Expand Down
13 changes: 10 additions & 3 deletions plugins/node/instrumentation-amqplib/test/amqplib-promise.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
13 changes: 10 additions & 3 deletions plugins/node/instrumentation-amqplib/test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 2 additions & 0 deletions plugins/node/instrumentation-amqplib/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,5 @@ export const asyncConsume = (
)
);
};

export const shouldTest = !!process.env.RUN_RABBIT_TESTS;

0 comments on commit 1c916e4

Please sign in to comment.