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

Commit a680d87

Browse files
authored
fix flakiness in test-debuglet.js (#207)
* A setTimeout that doesn't dominate the async done() path causes flakiness. * Improve the test to be more on-topic.
1 parent 80cd5a1 commit a680d87

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

src/agent/debuglet.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ module.exports = Debuglet;
5252
* @event 'started' once the startup tasks are completed
5353
* @event 'registered' once successfully registered to the debug api
5454
* @event 'stopped' if the agent stops due to a fatal error after starting
55+
* @event 'remotelyDisabled' if the debuggee is disabled by the server.
5556
* @constructor
5657
*/
5758
function Debuglet(debug, config) {
@@ -330,6 +331,7 @@ Debuglet.prototype.scheduleRegistration_ = function(seconds) {
330331
if (result.debuggee.isDisabled) {
331332
// Server has disabled this debuggee / debug agent.
332333
onError(new Error('Disabled by the server'));
334+
that.emit('remotelyDisabled');
333335
return;
334336
}
335337

test/standalone/test-debuglet.js

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,31 @@ describe(__filename, function() {
215215
{projectId: 'fake-project', credentials: fakeCredentials});
216216
debuglet = new Debuglet(debug, defaultConfig);
217217

218+
nocks.oauth2();
219+
var scope = nock(API)
220+
.post(REGISTER_PATH)
221+
.reply(200, {
222+
debuggee: {
223+
id: DEBUGGEE_ID,
224+
isDisabled: true
225+
}
226+
});
227+
228+
debuglet.once('remotelyDisabled', function() {
229+
assert.ok(!debuglet.fetcherActive_);
230+
scope.done();
231+
done();
232+
});
233+
234+
debuglet.start();
235+
});
236+
237+
it('should retry after a isDisabled request', function(done) {
238+
this.timeout(4000);
239+
var debug = require('../..')(
240+
{projectId: 'fake-project', credentials: fakeCredentials});
241+
debuglet = new Debuglet(debug, defaultConfig);
242+
218243
nocks.oauth2();
219244
var scope = nock(API)
220245
.post(REGISTER_PATH)
@@ -231,19 +256,19 @@ describe(__filename, function() {
231256
}
232257
});
233258

259+
var gotDisabled = false;
260+
debuglet.once('remotelyDisabled', function() {
261+
assert.ok(!debuglet.fetcherActive_);
262+
gotDisabled = true;
263+
});
264+
234265
debuglet.once('registered', function(id) {
266+
assert.ok(gotDisabled);
235267
assert.equal(id, DEBUGGEE_ID);
236-
setImmediate(function() {
237-
assert.ok(debuglet.fetcherActive_);
238-
scope.done();
239-
done();
240-
});
268+
scope.done();
269+
done();
241270
});
242271

243-
setTimeout(function() {
244-
assert.ok(!debuglet.fetcherActive_);
245-
}, 1000);
246-
247272
debuglet.start();
248273
});
249274

0 commit comments

Comments
 (0)