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

Commit 66e5786

Browse files
Avoid doubly expiring breakpoints (#157)
PR-URL: #157
1 parent 7cfffa6 commit 66e5786

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

lib/debuglet.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,10 @@ Debuglet.prototype.updateActiveBreakpoints_ = function(breakpoints) {
269269
that.completeBreakpoint_(breakpoint);
270270
}
271271
});
272-
}
273272

274-
// Schedule the expiry of server breakpoints.
275-
that.scheduleBreakpointExpiry_(breakpoint);
273+
// Schedule the expiry of server breakpoints.
274+
that.scheduleBreakpointExpiry_(breakpoint);
275+
}
276276
});
277277

278278
// Remove completed breakpoints that the server no longer cares about.

test/standalone/test-debuglet.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,65 @@ describe(__filename, function(){
311311
debuglet.start();
312312
});
313313

314+
// This test catches regressions in a bug where the agent would
315+
// re-schedule an already expired breakpoint to expire if the
316+
// server listed the breakpoint as active (which it may do depending
317+
// on how quickly the expiry is processed).
318+
// The test expires a breakpoint and then has the api respond with
319+
// the breakpoint listed as active. It validates that the breakpoint
320+
// is only expired with the server once.
321+
it('should not update expired breakpoints', function(done) {
322+
var oldTimeout = config.breakpointExpirationSec;
323+
var oldFetchRate = config.breakpointUpdateIntervalSec;
324+
config.breakpointExpirationSec = 1;
325+
config.breakpointUpdateIntervalSec = 1;
326+
this.timeout(6000);
327+
var debuglet = new Debuglet(
328+
config, logger.create(config.logLevel, '@google/cloud-debug'));
329+
330+
var scope = nock(API)
331+
.post(REGISTER_PATH)
332+
.reply(200, {
333+
debuggee: {
334+
id: DEBUGGEE_ID
335+
}
336+
})
337+
.get(BPS_PATH + '?success_on_timeout=true')
338+
.reply(200, {
339+
breakpoints: [bp]
340+
})
341+
.put(BPS_PATH + '/test', function(body) {
342+
return body.breakpoint.status.description.format ===
343+
'The snapshot has expired';
344+
})
345+
.reply(200)
346+
.get(BPS_PATH + '?success_on_timeout=true').times(4)
347+
.reply(200, {
348+
breakpoints: [bp]
349+
});
350+
351+
debuglet.once('started', function() {
352+
debuglet.debugletApi_.request_ = request; // Avoid authing.
353+
});
354+
debuglet.once('registered', function(id) {
355+
assert(id === DEBUGGEE_ID);
356+
setTimeout(function() {
357+
assert.deepEqual(debuglet.activeBreakpointMap_.test, bp);
358+
setTimeout(function() {
359+
assert(!debuglet.activeBreakpointMap_.test);
360+
// Fetcher disables if we re-update since endpoint isn't mocked twice
361+
assert(debuglet.fetcherActive_);
362+
scope.done();
363+
config.breakpointExpirationSec = oldTimeout;
364+
config.breakpointUpdateIntervalSec = oldFetchRate;
365+
done();
366+
}, 4500);
367+
}, 500);
368+
});
369+
370+
debuglet.start();
371+
});
372+
314373
describe('map subtract', function() {
315374
it('should be correct', function() {
316375
var a = { a: 1, b: 2 };

0 commit comments

Comments
 (0)