Skip to content

Commit

Permalink
fix: Account for auth spans in system test (googleapis#547)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewloring authored Aug 30, 2017
1 parent 0e15b6c commit 471902a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 10 additions & 2 deletions system-test/trace-express.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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];

Expand Down
3 changes: 2 additions & 1 deletion test/plugins/test-trace-google-gax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 471902a

Please sign in to comment.