Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
test: use unique service context for e2e tests (#638)
Browse files Browse the repository at this point in the history
Concurrent execution of the e2e tests is causing flakiness.
Making minor improvements to make it easier to debug.
  • Loading branch information
ofrobots authored Feb 15, 2019
1 parent 8a9ea83 commit 671317e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/debuggee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class Debuggee {
// TODO: This doesn't seem to ever be set but is referenced in the
// debuglet.ts file.
isDisabled?: boolean;
isInactive?: boolean;

/**
* Creates a Debuggee service object.
Expand Down
10 changes: 7 additions & 3 deletions system-test/test-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ describe('@google-cloud/debug end-to-end behavior', () => {

for (let i = 0; i < CLUSTER_WORKERS; i++) {
// Fork child processes that sned messages to this process with IPC.
// We pass UUID to the children so that they can all get the same
// debuggee id.
const child: Child = {transcript: ''};
child.process = cp.fork(
FILENAME, /* args */[],
FILENAME, /* args */[UUID],
{execArgv: [], env: process.env, silent: true});
child.process.on('message', handler);

Expand Down Expand Up @@ -139,7 +141,9 @@ describe('@google-cloud/debug end-to-end behavior', () => {
});

async function verifyDebuggeeFound() {
const debuggees = await api.listDebuggees(projectId!, true);
const allDebuggees = await api.listDebuggees(projectId!, true);
const debuggees =
allDebuggees.filter(debuggee => debuggee.isInactive !== true);

// Check that the debuggee created in this test is among the list of
// debuggees, then list its breakpoints
Expand Down Expand Up @@ -255,7 +259,7 @@ describe('@google-cloud/debug end-to-end behavior', () => {
console.log('-- checking log point was hit again');
children.forEach((child) => {
const count = (child.transcript.match(REGEX) || []).length;
assert.ok(count > 60);
assert.ok(count > 60, `expected count ${count} to be > 60`);
});
console.log('-- test passed');
}
Expand Down
13 changes: 8 additions & 5 deletions test/fixtures/fib.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ function fib(n) {
* limitations under the License.
*/

const uuid = require('uuid');
const nocks = require('../nocks.js');
nocks.projectId('fake-project-id');
// mock the metadata instance to uniformly make this look like a non-gcp
// environment.
nocks.metadataInstance();

const UUID = process.argv[2] || uuid.v4();

var debuglet = require('../../..').start({
debug: {
Expand All @@ -31,12 +37,9 @@ var debuglet = require('../../..').start({
logDelaySeconds: 5,
breakpointUpdateIntervalSec: 1,
testMode_: true,
allowExpressions: true
allowExpressions: true,
description: UUID
},
serviceContext: {
service: 'cloud-debug-system-test-service',
version: 'unversioned'
}
});

// Make troubleshooting easier if run by itself
Expand Down
6 changes: 6 additions & 0 deletions test/nocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@ export function projectId(reply: string): nock.Scope {
.once()
.reply(200, reply);
}

export function metadataInstance(): nock.Scope {
return nock('http://metadata.google.internal/')
.get('/computeMetadata/v1/instance')
.replyWithError({code: 'ENOTFOUND', message: 'nocked request'});
}

0 comments on commit 671317e

Please sign in to comment.