Skip to content

Commit

Permalink
test: pubsub
Browse files Browse the repository at this point in the history
  • Loading branch information
naseemkullah committed Dec 21, 2019
1 parent 3b47e26 commit 7b3a94e
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions packages/opentelemetry-plugin-ioredis/test/ioredis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,58 @@ describe('ioredis', () => {
});
});

it('should create a child span for pubsub', async () => {
const span = tracer.startSpan('test span');
await tracer.withSpan(span, async () => {
try {
const pub = new ioredis(URL);
const sub = new ioredis(URL);
await sub.subscribe('news', 'music');
await pub.publish('news', 'Hello world!');
await pub.publish('music', 'Hello again!');
await sub.unsubscribe('news', 'music');
await sub.disconnect(); // No span
await pub.disconnect(); // No span
const endedSpans = memoryExporter.getFinishedSpans();
assert.strictEqual(endedSpans.length, 9);
span.end();
assert.strictEqual(endedSpans.length, 10);
const spanNames = [
'connect',
'connect',
'subscribe',
'info',
'info',
'subscribe',
'publish',
'publish',
'unsubscribe',
'test span',
];
let i = 0;
while (i < 10) {
assert.strictEqual(endedSpans[i].name, spanNames[i]);
i++;
}

const attributes = {
...DEFAULT_ATTRIBUTES,
[AttributeNames.DB_STATEMENT]: 'subscribe news music',
};
assertionUtils.assertSpan(
endedSpans[5],
SpanKind.CLIENT,
attributes,
[],
okStatus
);
assertionUtils.assertPropagation(endedSpans[0], span);
} catch (error) {
assert.ifError(error);
}
});
});

it(`should create a child span for lua`, done => {
const attributes = {
...DEFAULT_ATTRIBUTES,
Expand Down

0 comments on commit 7b3a94e

Please sign in to comment.