From 0a06342fa1b2ba5c6c527085ec4a5b74a2e0519c Mon Sep 17 00:00:00 2001 From: Bartlomiej Obecny Date: Tue, 15 Dec 2020 20:12:35 +0100 Subject: [PATCH] chore: fixing tests --- .circleci/checksum.sh | 5 ++ .circleci/config.yml | 18 +++++-- .github/workflows/lint.yml | 5 +- .../package.json | 2 +- .../test/pg-pool.test.ts | 51 ++++++++++++++----- .../test/GrpcCensusPropagator.test.ts | 6 +++ 6 files changed, 67 insertions(+), 20 deletions(-) diff --git a/.circleci/checksum.sh b/.circleci/checksum.sh index af2e0f293e..9c9f3288c1 100644 --- a/.circleci/checksum.sh +++ b/.circleci/checksum.sh @@ -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 diff --git a/.circleci/config.yml b/.circleci/config.yml index d3c602ad6e..0ccf82e727 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4c08b33a6a..1299c32578 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -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 diff --git a/detectors/node/opentelemetry-resource-detector-github/package.json b/detectors/node/opentelemetry-resource-detector-github/package.json index 84447f0d40..1243086f9d 100644 --- a/detectors/node/opentelemetry-resource-detector-github/package.json +++ b/detectors/node/opentelemetry-resource-detector-github/package.json @@ -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" }, diff --git a/plugins/node/opentelemetry-plugin-pg-pool/test/pg-pool.test.ts b/plugins/node/opentelemetry-plugin-pg-pool/test/pg-pool.test.ts index 41e82a272e..6df836c2aa 100644 --- a/plugins/node/opentelemetry-plugin-pg-pool/test/pg-pool.test.ts +++ b/plugins/node/opentelemetry-plugin-pg-pool/test/pg-pool.test.ts @@ -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 ) => { @@ -97,11 +97,12 @@ describe('pg-pool@2.x', () => { 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 @@ -113,14 +114,15 @@ describe('pg-pool@2.x', () => { if (testPostgresLocally) { testUtils.startDocker('postgres'); } - done(); }); after(done => { if (testPostgresLocally) { testUtils.cleanUpDocker('postgres'); } + console.log('ending pool'); pool.end(() => { + console.log('pool ended'); done(); }); }); @@ -161,11 +163,11 @@ describe('pg-pool@2.x', () => { 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(); } @@ -197,14 +199,28 @@ describe('pg-pool@2.x', () => { 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(); }); }); @@ -227,8 +243,8 @@ describe('pg-pool@2.x', () => { 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'); }); }); @@ -251,8 +267,15 @@ describe('pg-pool@2.x', () => { 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'); diff --git a/propagators/opentelemetry-propagator-grpc-census-binary/test/GrpcCensusPropagator.test.ts b/propagators/opentelemetry-propagator-grpc-census-binary/test/GrpcCensusPropagator.test.ts index e64e6f095c..a5b44d9aa0 100644 --- a/propagators/opentelemetry-propagator-grpc-census-binary/test/GrpcCensusPropagator.test.ts +++ b/propagators/opentelemetry-propagator-grpc-census-binary/test/GrpcCensusPropagator.test.ts @@ -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() {