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

Commit

Permalink
fix flakiness in test-debuglet.js (#207)
Browse files Browse the repository at this point in the history
* A setTimeout that doesn't dominate the async done() path causes
  flakiness.
* Improve the test to be more on-topic.
  • Loading branch information
ofrobots committed Dec 22, 2016
1 parent 80cd5a1 commit a680d87
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/agent/debuglet.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module.exports = Debuglet;
* @event 'started' once the startup tasks are completed
* @event 'registered' once successfully registered to the debug api
* @event 'stopped' if the agent stops due to a fatal error after starting
* @event 'remotelyDisabled' if the debuggee is disabled by the server.
* @constructor
*/
function Debuglet(debug, config) {
Expand Down Expand Up @@ -330,6 +331,7 @@ Debuglet.prototype.scheduleRegistration_ = function(seconds) {
if (result.debuggee.isDisabled) {
// Server has disabled this debuggee / debug agent.
onError(new Error('Disabled by the server'));
that.emit('remotelyDisabled');
return;
}

Expand Down
43 changes: 34 additions & 9 deletions test/standalone/test-debuglet.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,31 @@ describe(__filename, function() {
{projectId: 'fake-project', credentials: fakeCredentials});
debuglet = new Debuglet(debug, defaultConfig);

nocks.oauth2();
var scope = nock(API)
.post(REGISTER_PATH)
.reply(200, {
debuggee: {
id: DEBUGGEE_ID,
isDisabled: true
}
});

debuglet.once('remotelyDisabled', function() {
assert.ok(!debuglet.fetcherActive_);
scope.done();
done();
});

debuglet.start();
});

it('should retry after a isDisabled request', function(done) {
this.timeout(4000);
var debug = require('../..')(
{projectId: 'fake-project', credentials: fakeCredentials});
debuglet = new Debuglet(debug, defaultConfig);

nocks.oauth2();
var scope = nock(API)
.post(REGISTER_PATH)
Expand All @@ -231,19 +256,19 @@ describe(__filename, function() {
}
});

var gotDisabled = false;
debuglet.once('remotelyDisabled', function() {
assert.ok(!debuglet.fetcherActive_);
gotDisabled = true;
});

debuglet.once('registered', function(id) {
assert.ok(gotDisabled);
assert.equal(id, DEBUGGEE_ID);
setImmediate(function() {
assert.ok(debuglet.fetcherActive_);
scope.done();
done();
});
scope.done();
done();
});

setTimeout(function() {
assert.ok(!debuglet.fetcherActive_);
}, 1000);

debuglet.start();
});

Expand Down

0 comments on commit a680d87

Please sign in to comment.