From 471902a43868e8474811de535dce4153d6226065 Mon Sep 17 00:00:00 2001 From: Matthew Loring Date: Wed, 30 Aug 2017 11:36:04 -0700 Subject: [PATCH] fix: Account for auth spans in system test (#547) PR-URL: https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/pull/547 --- system-test/trace-express.js | 12 ++++++++++-- test/plugins/test-trace-google-gax.js | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/system-test/trace-express.js b/system-test/trace-express.js index 3da85f90a..c6c973f76 100644 --- a/system-test/trace-express.js +++ b/system-test/trace-express.js @@ -40,6 +40,10 @@ const googleAuth = require('google-auto-auth'); const got = require('got'); const queryString = require('querystring'); const uuid = require('uuid'); +const semver = require('semver'); + +const usingAsyncHooks = semver.satisfies(process.version, '>=8') && + process.env.GCLOUD_TRACE_NEW_CONTEXT; // TODO(ofrobots): this code should be moved to a better location. Perhaps // google-auto-auth or google-auth-library. @@ -128,8 +132,12 @@ describe('express + datastore', () => { assert.equal(traces.length, 1, 'there should be exactly one trace'); const trace = traces[0]; - console.log(trace); - assert.equal(trace.spans.length, 2, 'should be 2 spans: parent, child'); + if (usingAsyncHooks) { + assert.equal(trace.spans.length, 3, 'should be 3 spans: parent, child, auth'); + assert.equal(trace.spans[2].name, 'accounts.google.com'); + } else { + assert.equal(trace.spans.length, 2, 'should be 2 spans: parent, child'); + } const parent = trace.spans[0]; const child = trace.spans[1]; diff --git a/test/plugins/test-trace-google-gax.js b/test/plugins/test-trace-google-gax.js index 732e67c41..cc2be97f3 100644 --- a/test/plugins/test-trace-google-gax.js +++ b/test/plugins/test-trace-google-gax.js @@ -47,7 +47,8 @@ describe('google-gax', function() { endRootSpan(); // Authentication will fail due to invalid credentials but a span will still be // generated. - assert.equal(err.message, 'invalid_client'); + assert.equal(err.message, + 'Getting metadata from plugin failed with error: invalid_client'); assert.equal(err.code, 16); var span = common.getMatchingSpan(function(span) { return span.kind === 'RPC_CLIENT' && span.name.indexOf('grpc:') === 0;