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

chore(mysql2): adding TAV script #641

Merged
merged 8 commits into from Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/opentelemetry-test-utils/test-utils.ts
Expand Up @@ -28,6 +28,7 @@ import {
hrTimeToMilliseconds,
hrTimeToMicroseconds,
} from '@opentelemetry/core';
import * as path from 'path';

const dockerRunCmds = {
cassandra:
Expand Down Expand Up @@ -135,3 +136,9 @@ export interface TimedEvent {
/** The attributes of the event. */
attributes?: SpanAttributes;
}

export const getPackageVersion = (packageName: string) => {
const packagePath = require.resolve(packageName);
const packageJsonPath = path.join(path.dirname(packagePath), 'package.json');
return require(packageJsonPath).version;
};
6 changes: 6 additions & 0 deletions plugins/node/opentelemetry-instrumentation-mysql2/.tav.yml
@@ -0,0 +1,6 @@
mysql2:
versions: 2.*
commands: npm run test

# Fix missing `test-utils` package
pretest: npm run --prefix ../../../ lerna:link
Expand Up @@ -15,6 +15,7 @@
"prepare": "npm run compile",
"tdd": "npm run test -- --watch-extensions ts --watch",
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'",
"test-all-versions": "tav",
"version:update": "node ../../../scripts/version-update.js"
},
"keywords": [
Expand Down Expand Up @@ -58,6 +59,7 @@
"mysql2": "2.3.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
Expand Up @@ -27,6 +27,7 @@ import {
import * as assert from 'assert';
import { MySQL2Instrumentation } from '../src';

const LIB_VERSION = testUtils.getPackageVersion('mysql2');
const port = Number(process.env.MYSQL_PORT) || 33306;
const database = process.env.MYSQL_DATABASE || 'test_db';
const host = process.env.MYSQL_HOST || '127.0.0.1';
Expand Down Expand Up @@ -117,11 +118,16 @@ describe('mysql@2.x', () => {
instrumentation.disable();
connection.end(() => {
pool.end(() => {
// PoolCluster.end types in the package are invalid
// https://github.com/sidorares/node-mysql2/pull/1332
(poolCluster as any).end(() => {
if (isPoolClusterEndIgnoreCallback()) {
poolCluster.end();
done();
});
} else {
// PoolCluster.end types in the package are invalid
// https://github.com/sidorares/node-mysql2/pull/1332
(poolCluster as any).end(() => {
done();
});
}
});
});
});
Expand Down Expand Up @@ -659,3 +665,9 @@ function assertSpan(
assert.strictEqual(span.status.code, SpanStatusCode.ERROR);
}
}

function isPoolClusterEndIgnoreCallback() {
// Since v2.2.0 `end` function respect callback
// https://github.com/sidorares/node-mysql2/commit/1481015626e506754adc4308e5508356a3a03aa0
return ['2.0.0', '2.0.1', '2.0.2', '2.1.0'].includes(LIB_VERSION);
}