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

feat: test-utils #644

Merged
merged 8 commits into from
Dec 24, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/opentelemetry-plugin-mysql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
},
"devDependencies": {
"@opentelemetry/node": "^0.3.1",
"@opentelemetry/test-utils": "^0.3.1",
"@opentelemetry/tracing": "^0.3.1",
"@types/mocha": "^5.2.7",
"@types/mysql": "^2.15.4",
Expand Down
6 changes: 3 additions & 3 deletions packages/opentelemetry-plugin-mysql/test/mysql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
import * as assert from 'assert';
import * as mysql from 'mysql';
import { MysqlPlugin, plugin } from '../src';
import * as testUtils from './testUtils';
import * as testUtils from '@opentelemetry/test-utils';
import { AttributeNames } from '../src/enums';
import { CanonicalCode } from '@opentelemetry/types';

Expand Down Expand Up @@ -54,7 +54,7 @@ describe('[email protected]', () => {
}
tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter));
if (testMysqlLocally) {
testUtils.startDocker();
testUtils.startDocker('mysql');
// wait 15 seconds for docker container to start
this.timeout(20000);
setTimeout(done, 15000);
Expand All @@ -66,7 +66,7 @@ describe('[email protected]', () => {
after(function() {
if (testMysqlLocally) {
this.timeout(5000);
testUtils.cleanUpDocker();
testUtils.cleanUpDocker('mysql');
}
});

Expand Down
55 changes: 0 additions & 55 deletions packages/opentelemetry-plugin-mysql/test/testUtils.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
},
"devDependencies": {
"@opentelemetry/plugin-pg": "^0.3.1",
"@opentelemetry/test-utils": "^0.3.1",
"@types/mocha": "^5.2.7",
"@types/node": "^12.6.9",
"@types/pg": "^7.11.2",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,21 @@ import {
InMemorySpanExporter,
SimpleSpanProcessor,
} from '@opentelemetry/tracing';
import { SpanKind, Attributes, TimedEvent, Span } from '@opentelemetry/types';
import {
SpanKind,
Attributes,
TimedEvent,
Span,
CanonicalCode,
Status,
} from '@opentelemetry/types';
import { plugin as pgPlugin, PostgresPlugin } from '@opentelemetry/plugin-pg';
import { plugin, PostgresPoolPlugin } from '../src';
import { AttributeNames } from '../src/enums';
import * as assert from 'assert';
import * as pg from 'pg';
import * as pgPool from 'pg-pool';
import * as assertionUtils from './assertionUtils';
import * as testUtils from './testUtils';
import * as testUtils from '@opentelemetry/test-utils';

const memoryExporter = new InMemorySpanExporter();

Expand Down Expand Up @@ -65,18 +71,23 @@ const DEFAULT_PG_ATTRIBUTES = {
[AttributeNames.DB_USER]: CONFIG.user,
};

const okStatus: Status = {
code: CanonicalCode.OK,
};

const runCallbackTest = (
parentSpan: Span,
attributes: Attributes,
events: TimedEvent[],
status: Status = okStatus,
spansLength = 1,
spansIndex = 0
) => {
const spans = memoryExporter.getFinishedSpans();
assert.strictEqual(spans.length, spansLength);
const pgSpan = spans[spansIndex];
assertionUtils.assertSpan(pgSpan, SpanKind.CLIENT, attributes, events);
assertionUtils.assertPropagation(pgSpan, parentSpan);
testUtils.assertSpan(pgSpan, SpanKind.CLIENT, attributes, events, status);
testUtils.assertPropagation(pgSpan, parentSpan);
};

describe('[email protected]', () => {
Expand All @@ -97,14 +108,14 @@ describe('[email protected]', () => {
pool = new pgPool(CONFIG);
tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter));
if (testPostgresLocally) {
testUtils.startDocker();
testUtils.startDocker('postgres');
}
done();
});

after(function(done) {
if (testPostgresLocally) {
testUtils.cleanUpDocker();
testUtils.cleanUpDocker('postgres');
}
pool.end(() => {
done();
Expand Down Expand Up @@ -144,11 +155,11 @@ describe('[email protected]', () => {
const span = tracer.startSpan('test span');
await tracer.withSpan(span, async () => {
const client = await pool.connect();
runCallbackTest(span, pgPoolattributes, events, 1, 0);
runCallbackTest(span, pgPoolattributes, events, okStatus, 1, 0);
assert.ok(client, 'pool.connect() returns a promise');
try {
await client.query('SELECT NOW()');
runCallbackTest(span, pgAttributes, events, 2, 1);
runCallbackTest(span, pgAttributes, events, okStatus, 2, 1);
} catch (e) {
throw e;
} finally {
Expand All @@ -175,13 +186,13 @@ describe('[email protected]', () => {
}
release();
assert.ok(client);
runCallbackTest(parentSpan, pgPoolattributes, events, 1, 0);
runCallbackTest(parentSpan, pgPoolattributes, events, okStatus, 1, 0);
client.query('SELECT NOW()', (err, ret) => {
if (err) {
return done(err);
}
assert.ok(ret);
runCallbackTest(parentSpan, pgAttributes, events, 2, 1);
runCallbackTest(parentSpan, pgAttributes, events, okStatus, 2, 1);
done();
});
});
Expand All @@ -205,8 +216,8 @@ describe('[email protected]', () => {
await tracer.withSpan(span, async () => {
try {
const result = await pool.query('SELECT NOW()');
runCallbackTest(span, pgPoolattributes, events, 2, 0);
runCallbackTest(span, pgAttributes, events, 2, 1);
runCallbackTest(span, pgPoolattributes, events, okStatus, 2, 0);
runCallbackTest(span, pgAttributes, events, okStatus, 2, 1);
assert.ok(result, 'pool.query() returns a promise');
} catch (e) {
throw e;
Expand All @@ -230,8 +241,8 @@ describe('[email protected]', () => {
if (err) {
return done(err);
}
runCallbackTest(parentSpan, pgPoolattributes, events, 2, 0);
runCallbackTest(parentSpan, pgAttributes, events, 2, 1);
runCallbackTest(parentSpan, pgPoolattributes, events, okStatus, 2, 0);
runCallbackTest(parentSpan, pgAttributes, events, okStatus, 2, 1);
done();
});
assert.strictEqual(resNoPromise, undefined, 'No promise is returned');
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"access": "public"
},
"devDependencies": {
"@opentelemetry/test-utils": "^0.3.1",
"@opentelemetry/node": "^0.3.1",
"@opentelemetry/tracing": "^0.3.1",
"@types/mocha": "^5.2.7",
Expand Down
Loading