Skip to content

Commit

Permalink
chore: fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
obecny committed Dec 15, 2020
1 parent 5b2015f commit 0a06342
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .circleci/checksum.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ fi

openssl md5 package.json >> $FILE

find detectors/node/*/package.json | xargs -I{} openssl md5 {} >> $FILE
find metapackages/*/package.json | xargs -I{} openssl md5 {} >> $FILE
find packages/*/package.json | xargs -I{} openssl md5 {} >> $FILE
find plugins/node/*/package.json | xargs -I{} openssl md5 {} >> $FILE
find plugins/web/*/package.json | xargs -I{} openssl md5 {} >> $FILE
find propagators/*/package.json | xargs -I{} openssl md5 {} >> $FILE

sort -o $FILE $FILE
18 changes: 14 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,26 @@ cache_1: &cache_1
paths:
- ./node_modules
- ./package-lock.json
- detectors/node/opentelemetry-resource-detector-github/node_modules
- metapackages/plugins-node-core-and-contrib/node_modules
- packages/opentelemetry-host-metrics/node_modules
- packages/opentelemetry-test-utils/node_modules
- plugins/node/opentelemetry-hapi-instrumentation/node_modules
- plugins/node/opentelemetry-instrumentation-graphql/node_modules
- plugins/node/opentelemetry-koa-instrumentation/node_modules
- plugins/node/opentelemetry-plugin-dns/node_modules
- plugins/node/opentelemetry-plugin-express/node_modules
- plugins/node/opentelemetry-plugin-ioredis/node_modules
- plugins/node/opentelemetry-plugin-mongodb/node_modules
- plugins/node/opentelemetry-plugin-redis/node_modules
- plugins/node/opentelemetry-plugin-mysql/node_modules
- plugins/node/opentelemetry-plugin-pg/node_modules
- plugins/node/opentelemetry-plugin-document-load/node_modules
- plugins/node/opentelemetry-plugin-pg-pool/node_modules
- plugins/node/opentelemetry-plugin-mysql/node_modules
- plugins/node/opentelemetry-plugin-express/node_modules
- plugins/node/opentelemetry-plugin-redis/node_modules
- plugins/web/opentelemetry-plugin-document-load/node_modules
- plugins/web/opentelemetry-plugin-react-load/node_modules
- plugins/web/opentelemetry-plugin-user-interaction/node_modules
- propagators/opentelemetry-propagator-jaeger/node_modules
- propagators/opentelemetry-propagator-grpc-census-binary/node_modules

node_unit_tests: &node_unit_tests
resource_class: large
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ jobs:
id: cache
with:
path: |
./node_modules
./package-lock.json
node_modules
packages/*/node_modules
detectors/node/*/node_modules
metapackages/*/node_modules
packages/*/node_modules
plugins/node/*/node_modules
plugins/web/*/node_modules
propagators/*/node_modules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"nyc": "15.1.0",
"rimraf": "3.0.2",
"sinon": "9.0.2",
"ts-mocha": "7.0.0",
"ts-mocha": "8.0.0",
"ts-node": "8.10.2",
"typescript": "3.9.7"
},
Expand Down
51 changes: 37 additions & 14 deletions plugins/node/opentelemetry-plugin-pg-pool/test/pg-pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ const DEFAULT_PG_ATTRIBUTES = {
[AttributeNames.DB_USER]: CONFIG.user,
};

const okStatus: Status = {
code: StatusCode.OK,
const unsetStatus: Status = {
code: StatusCode.UNSET,
};

const runCallbackTest = (
parentSpan: Span,
attributes: Attributes,
events: TimedEvent[],
status: Status = okStatus,
status: Status = unsetStatus,
spansLength = 1,
spansIndex = 0
) => {
Expand All @@ -97,11 +97,12 @@ describe('[email protected]', () => {
let contextManager: AsyncHooksContextManager;
const provider = new BasicTracerProvider();
const logger = new NoopLogger();
const testPostgres = process.env.RUN_POSTGRES_TESTS; // For CI: assumes local postgres db is already available
const testPostgres = process.env.RUN_POSTGRES_TESTS; // For CI:
// assumes local postgres db is already available
const testPostgresLocally = process.env.RUN_POSTGRES_TESTS_LOCAL; // For local: spins up local postgres db via docker
const shouldTest = testPostgres || testPostgresLocally; // Skips these tests if false (default)

before(function (done) {
before(function () {
if (!shouldTest) {
// this.skip() workaround
// https://github.com/mochajs/mocha/issues/2683#issuecomment-375629901
Expand All @@ -113,14 +114,15 @@ describe('[email protected]', () => {
if (testPostgresLocally) {
testUtils.startDocker('postgres');
}
done();
});

after(done => {
if (testPostgresLocally) {
testUtils.cleanUpDocker('postgres');
}
console.log('ending pool');
pool.end(() => {
console.log('pool ended');
done();
});
});
Expand Down Expand Up @@ -161,11 +163,11 @@ describe('[email protected]', () => {
const span = provider.getTracer('test-pg-pool').startSpan('test span');
await provider.getTracer('test-pg-pool').withSpan(span, async () => {
const client = await pool.connect();
runCallbackTest(span, pgPoolattributes, events, okStatus, 1, 0);
runCallbackTest(span, pgPoolattributes, events, unsetStatus, 1, 0);
assert.ok(client, 'pool.connect() returns a promise');
try {
await client.query('SELECT NOW()');
runCallbackTest(span, pgAttributes, events, okStatus, 2, 1);
runCallbackTest(span, pgAttributes, events, unsetStatus, 2, 1);
} finally {
client.release();
}
Expand Down Expand Up @@ -197,14 +199,28 @@ describe('[email protected]', () => {
throw new Error('No client received');
}
assert.ok(client);
runCallbackTest(parentSpan, pgPoolattributes, events, okStatus, 1, 0);
runCallbackTest(
parentSpan,
pgPoolattributes,
events,
unsetStatus,
1,
0
);
client.query('SELECT NOW()', (err, ret) => {
release();
if (err) {
return done(err);
}
assert.ok(ret);
runCallbackTest(parentSpan, pgAttributes, events, okStatus, 2, 1);
runCallbackTest(
parentSpan,
pgAttributes,
events,
unsetStatus,
2,
1
);
done();
});
});
Expand All @@ -227,8 +243,8 @@ describe('[email protected]', () => {
const span = provider.getTracer('test-pg-pool').startSpan('test span');
await provider.getTracer('test-pg-pool').withSpan(span, async () => {
const result = await pool.query('SELECT NOW()');
runCallbackTest(span, pgPoolattributes, events, okStatus, 2, 0);
runCallbackTest(span, pgAttributes, events, okStatus, 2, 1);
runCallbackTest(span, pgPoolattributes, events, unsetStatus, 2, 0);
runCallbackTest(span, pgAttributes, events, unsetStatus, 2, 1);
assert.ok(result, 'pool.query() returns a promise');
});
});
Expand All @@ -251,8 +267,15 @@ describe('[email protected]', () => {
if (err) {
return done(err);
}
runCallbackTest(parentSpan, pgPoolattributes, events, okStatus, 2, 0);
runCallbackTest(parentSpan, pgAttributes, events, okStatus, 2, 1);
runCallbackTest(
parentSpan,
pgPoolattributes,
events,
unsetStatus,
2,
0
);
runCallbackTest(parentSpan, pgAttributes, events, unsetStatus, 2, 1);
done();
});
assert.strictEqual(resNoPromise, undefined, 'No promise is returned');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ describe('GrpcCensusPropagator', () => {
assert.deepStrictEqual(extractedSpanContext, undefined);
});
});

describe('fields', () => {
it('should return valid values', () => {
assert.deepStrictEqual(censusPropagator.fields(), ['grpc-trace-bin']);
});
});
});

function getUnsampledSpanEncodedArray() {
Expand Down

0 comments on commit 0a06342

Please sign in to comment.