Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(ioredis): make flaky test deterministic #342

Merged
merged 4 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -364,25 +364,28 @@ describe('ioredis', () => {
const span = provider.getTracer('ioredis-test').startSpan('test span');
await context.with(setSpan(context.active(), span), async () => {
try {
const pub = new ioredis(URL);
const sub = new ioredis(URL);
// use lazyConnect so we can call the `connect` function and await it.
// this ensures that all operations are sequential and predictable.
const pub = new ioredis(URL, { lazyConnect: true });
await pub.connect();
const sub = new ioredis(URL, { lazyConnect: true });
await sub.connect();
await sub.subscribe('news', 'music');
await pub.publish('news', 'Hello world!');
await pub.publish('music', 'Hello again!');
await sub.unsubscribe('news', 'music');
await sub.quit();
await pub.quit();
const endedSpans = memoryExporter.getFinishedSpans();
assert.strictEqual(endedSpans.length, 11);
assert.strictEqual(endedSpans.length, 10);
span.end();
assert.strictEqual(endedSpans.length, 12);
assert.strictEqual(endedSpans.length, 11);
const spanNames = [
'connect',
'connect',
'info',
'connect',
'info',
'subscribe',
'subscribe',
'publish',
'publish',
'unsubscribe',
Expand All @@ -391,7 +394,7 @@ describe('ioredis', () => {
'test span',
];
let i = 0;
while (i < 12) {
while (i < 11) {
assert.strictEqual(endedSpans[i].name, spanNames[i]);
i++;
}
Expand All @@ -401,7 +404,7 @@ describe('ioredis', () => {
[DatabaseAttribute.DB_STATEMENT]: 'subscribe news music',
};
testUtils.assertSpan(
endedSpans[5],
endedSpans[4],
SpanKind.CLIENT,
attributes,
[],
Expand Down
19 changes: 11 additions & 8 deletions plugins/node/opentelemetry-plugin-ioredis/test/ioredis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,25 +357,28 @@ describe('ioredis', () => {
const span = provider.getTracer('ioredis-test').startSpan('test span');
await context.with(setSpan(context.active(), span), async () => {
try {
const pub = new ioredis(URL);
const sub = new ioredis(URL);
// use lazyConnect so we can call the `connect` function and await it.
// this ensures that all operations are sequential and predictable.
const pub = new ioredis(URL, { lazyConnect: true });
await pub.connect();
const sub = new ioredis(URL, { lazyConnect: true });
await sub.connect();
await sub.subscribe('news', 'music');
await pub.publish('news', 'Hello world!');
await pub.publish('music', 'Hello again!');
await sub.unsubscribe('news', 'music');
await sub.quit();
await pub.quit();
const endedSpans = memoryExporter.getFinishedSpans();
assert.strictEqual(endedSpans.length, 11);
assert.strictEqual(endedSpans.length, 10);
span.end();
assert.strictEqual(endedSpans.length, 12);
assert.strictEqual(endedSpans.length, 11);
const spanNames = [
'connect',
'connect',
'info',
'connect',
'info',
'subscribe',
'subscribe',
'publish',
'publish',
'unsubscribe',
Expand All @@ -384,7 +387,7 @@ describe('ioredis', () => {
'test span',
];
let i = 0;
while (i < 12) {
while (i < 11) {
assert.strictEqual(endedSpans[i].name, spanNames[i]);
i++;
}
Expand All @@ -394,7 +397,7 @@ describe('ioredis', () => {
[DatabaseAttribute.DB_STATEMENT]: 'subscribe news music',
};
testUtils.assertSpan(
endedSpans[5],
endedSpans[4],
SpanKind.CLIENT,
attributes,
[],
Expand Down