Skip to content

Commit

Permalink
Build: Add test-all-versions scripts to redis & ioredis (open-telemet…
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaniv Davidi committed Aug 25, 2021
1 parent ecde944 commit b213984
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 74 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"codecov:ci:changed": "lerna run codecov --since origin/main --parallel",
"codecov:browser": "lerna run codecov:browser",
"changelog": "lerna-changelog",
"lerna:link": "lerna link",
"lint": "lerna run lint",
"lint:fix": "lerna run lint:fix",
"lint:examples": "eslint ./examples/**/*.js",
Expand Down
7 changes: 7 additions & 0 deletions plugins/node/opentelemetry-instrumentation-ioredis/.tav.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ioredis:
# Ignoring v4.19.0. Tests never ends. Caused by https://github.com/luin/ioredis/pull/1219
versions: ">1 < 4.19.0 || > 4.19.0 < 5"
commands: npm run test

# Fix missing `test-utils` package
pretest: npm run --prefix ../../../ lerna:link
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'",
"test:debug": "cross-env RUN_REDIS_TESTS_LOCAL=true ts-mocha --inspect-brk --no-timeouts -p tsconfig.json 'test/**/*.test.ts'",
"test:local": "cross-env RUN_REDIS_TESTS_LOCAL=true npm run test",
"test-all-versions": "tav",
"test-all-versions:local": "cross-env RUN_REDIS_TESTS_LOCAL=true npm run test-all-versions",
"tdd": "npm run test -- --watch-extensions ts --watch",
"clean": "rimraf build/*",
"lint": "eslint . --ext .ts",
Expand Down Expand Up @@ -62,6 +64,7 @@
"mocha": "7.2.0",
"nyc": "15.1.0",
"rimraf": "3.0.2",
"test-all-versions": "5.0.1",
"ts-mocha": "8.0.0",
"typescript": "4.3.5"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ describe('ioredis', () => {
assert.strictEqual(endedSpans.length, 10);
span.end();
assert.strictEqual(endedSpans.length, 11);
const spanNames = [
const expectedSpanNames = [
'connect',
'info',
'connect',
Expand All @@ -400,11 +400,12 @@ describe('ioredis', () => {
'quit',
'test span',
];
let i = 0;
while (i < 11) {
assert.strictEqual(endedSpans[i].name, spanNames[i]);
i++;
}

const actualSpanNames = endedSpans.map(s => s.name);
assert.deepStrictEqual(
actualSpanNames.sort(),
expectedSpanNames.sort()
);

const attributes = {
...DEFAULT_ATTRIBUTES,
Expand All @@ -424,74 +425,6 @@ describe('ioredis', () => {
});
});

it('should create a child span for lua', done => {
const attributes = {
...DEFAULT_ATTRIBUTES,
[SemanticAttributes.DB_STATEMENT]: `evalsha bfbf458525d6a0b19200bfd6db3af481156b367b 1 ${testKeyName}`,
};

const span = provider.getTracer('ioredis-test').startSpan('test span');
context.with(trace.setSpan(context.active(), span), () => {
// This will define a command echo:
client.defineCommand('echo', {
numberOfKeys: 1,
lua: 'return {KEYS[1],ARGV[1]}',
});
// Now `echo` can be used just like any other ordinary command,
// and ioredis will try to use `EVALSHA` internally when possible for better performance.
client.echo(testKeyName, (err, result) => {
assert.ifError(err);

span.end();
const endedSpans = memoryExporter.getFinishedSpans();
const evalshaSpan = endedSpans[0];
// the script may be already cached on server therefore we get either 2 or 3 spans
if (endedSpans.length === 3) {
assert.strictEqual(endedSpans[2].name, 'test span');
assert.strictEqual(endedSpans[1].name, 'eval');
assert.strictEqual(endedSpans[0].name, 'evalsha');
// in this case, server returns NOSCRIPT error for evalsha,
// telling the client to use EVAL instead
sanitizeEventForAssertion(evalshaSpan);
testUtils.assertSpan(
evalshaSpan,
SpanKind.CLIENT,
attributes,
[
{
attributes: {
[SemanticAttributes.EXCEPTION_MESSAGE]:
'NOSCRIPT No matching script. Please use EVAL.',
[SemanticAttributes.EXCEPTION_STACKTRACE]:
predictableStackTrace,
[SemanticAttributes.EXCEPTION_TYPE]: 'ReplyError',
},
name: 'exception',
time: [0, 0],
},
],
{
code: SpanStatusCode.ERROR,
}
);
} else {
assert.strictEqual(endedSpans.length, 2);
assert.strictEqual(endedSpans[1].name, 'test span');
assert.strictEqual(endedSpans[0].name, 'evalsha');
testUtils.assertSpan(
evalshaSpan,
SpanKind.CLIENT,
attributes,
[],
unsetStatus
);
}
testUtils.assertPropagation(evalshaSpan, span);
done();
});
});
});

it('should create a child span for multi/transaction', done => {
const attributes = {
...DEFAULT_ATTRIBUTES,
Expand Down Expand Up @@ -619,11 +552,90 @@ describe('ioredis', () => {
}
});
});

it('should create a child span for lua', done => {
instrumentation = new IORedisInstrumentation({
requireParentSpan: false,
});
instrumentation.setTracerProvider(provider);
require('ioredis');

const attributes = {
...DEFAULT_ATTRIBUTES,
[SemanticAttributes.DB_STATEMENT]: `evalsha bfbf458525d6a0b19200bfd6db3af481156b367b 1 ${testKeyName}`,
};

const span = provider.getTracer('ioredis-test').startSpan('test span');
context.with(trace.setSpan(context.active(), span), () => {
// This will define a command echo:
client.defineCommand('echo', {
numberOfKeys: 1,
lua: 'return {KEYS[1],ARGV[1]}',
});
// Now `echo` can be used just like any other ordinary command,
// and ioredis will try to use `EVALSHA` internally when possible for better performance.
client.echo(testKeyName, (err, result) => {
assert.ifError(err);

span.end();
const endedSpans = memoryExporter.getFinishedSpans();
const evalshaSpan = endedSpans[0];
// the script may be already cached on server therefore we get either 2 or 3 spans
if (endedSpans.length === 3) {
assert.strictEqual(endedSpans[2].name, 'test span');
assert.strictEqual(endedSpans[1].name, 'eval');
assert.strictEqual(endedSpans[0].name, 'evalsha');
// in this case, server returns NOSCRIPT error for evalsha,
// telling the client to use EVAL instead
sanitizeEventForAssertion(evalshaSpan);
testUtils.assertSpan(
evalshaSpan,
SpanKind.CLIENT,
attributes,
[
{
attributes: {
[SemanticAttributes.EXCEPTION_MESSAGE]:
'NOSCRIPT No matching script. Please use EVAL.',
[SemanticAttributes.EXCEPTION_STACKTRACE]:
predictableStackTrace,
[SemanticAttributes.EXCEPTION_TYPE]: 'ReplyError',
},
name: 'exception',
time: [0, 0],
},
],
{
code: SpanStatusCode.ERROR,
}
);
} else {
assert.strictEqual(endedSpans.length, 2);
assert.strictEqual(endedSpans[1].name, 'test span');
assert.strictEqual(endedSpans[0].name, 'evalsha');
testUtils.assertSpan(
evalshaSpan,
SpanKind.CLIENT,
attributes,
[],
unsetStatus
);
}
testUtils.assertPropagation(evalshaSpan, span);
done();
});
});
});
});

describe('Instrumenting without parent span', () => {
before(() => {
instrumentation.disable();
instrumentation = new IORedisInstrumentation({
requireParentSpan: true,
});
instrumentation.setTracerProvider(provider);
require('ioredis');
instrumentation.enable();
});
it('should not create child span', async () => {
Expand Down
6 changes: 6 additions & 0 deletions plugins/node/opentelemetry-instrumentation-redis/.tav.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
redis:
versions: ^2.6.0 || ^3.0.0
commands: npm run test

# Fix missing `test-utils` package
pretest: npm run --prefix ../../../ lerna:link
3 changes: 3 additions & 0 deletions plugins/node/opentelemetry-instrumentation-redis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'",
"test:debug": "cross-env RUN_REDIS_TESTS_LOCAL=true ts-mocha --inspect-brk --no-timeouts -p tsconfig.json 'test/**/*.test.ts'",
"test:local": "cross-env RUN_REDIS_TESTS_LOCAL=true npm run test",
"test-all-versions": "tav",
"test-all-versions:local": "cross-env RUN_REDIS_TESTS_LOCAL=true npm run test-all-versions",
"tdd": "npm run test -- --watch-extensions ts --watch",
"clean": "rimraf build/*",
"lint": "eslint . --ext .ts",
Expand Down Expand Up @@ -61,6 +63,7 @@
"nyc": "15.1.0",
"redis": "3.1.2",
"rimraf": "3.0.2",
"test-all-versions": "5.0.1",
"ts-mocha": "8.0.0",
"typescript": "4.3.5"
},
Expand Down

0 comments on commit b213984

Please sign in to comment.