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

Commit

Permalink
Avoid doubly expiring breakpoints (#157)
Browse files Browse the repository at this point in the history
PR-URL: #157
  • Loading branch information
matthewloring committed Oct 11, 2016
1 parent 7cfffa6 commit 66e5786
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/debuglet.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@ Debuglet.prototype.updateActiveBreakpoints_ = function(breakpoints) {
that.completeBreakpoint_(breakpoint);
}
});
}

// Schedule the expiry of server breakpoints.
that.scheduleBreakpointExpiry_(breakpoint);
// Schedule the expiry of server breakpoints.
that.scheduleBreakpointExpiry_(breakpoint);
}
});

// Remove completed breakpoints that the server no longer cares about.
Expand Down
59 changes: 59 additions & 0 deletions test/standalone/test-debuglet.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,65 @@ describe(__filename, function(){
debuglet.start();
});

// This test catches regressions in a bug where the agent would
// re-schedule an already expired breakpoint to expire if the
// server listed the breakpoint as active (which it may do depending
// on how quickly the expiry is processed).
// The test expires a breakpoint and then has the api respond with
// the breakpoint listed as active. It validates that the breakpoint
// is only expired with the server once.
it('should not update expired breakpoints', function(done) {
var oldTimeout = config.breakpointExpirationSec;
var oldFetchRate = config.breakpointUpdateIntervalSec;
config.breakpointExpirationSec = 1;
config.breakpointUpdateIntervalSec = 1;
this.timeout(6000);
var debuglet = new Debuglet(
config, logger.create(config.logLevel, '@google/cloud-debug'));

var scope = nock(API)
.post(REGISTER_PATH)
.reply(200, {
debuggee: {
id: DEBUGGEE_ID
}
})
.get(BPS_PATH + '?success_on_timeout=true')
.reply(200, {
breakpoints: [bp]
})
.put(BPS_PATH + '/test', function(body) {
return body.breakpoint.status.description.format ===
'The snapshot has expired';
})
.reply(200)
.get(BPS_PATH + '?success_on_timeout=true').times(4)
.reply(200, {
breakpoints: [bp]
});

debuglet.once('started', function() {
debuglet.debugletApi_.request_ = request; // Avoid authing.
});
debuglet.once('registered', function(id) {
assert(id === DEBUGGEE_ID);
setTimeout(function() {
assert.deepEqual(debuglet.activeBreakpointMap_.test, bp);
setTimeout(function() {
assert(!debuglet.activeBreakpointMap_.test);
// Fetcher disables if we re-update since endpoint isn't mocked twice
assert(debuglet.fetcherActive_);
scope.done();
config.breakpointExpirationSec = oldTimeout;
config.breakpointUpdateIntervalSec = oldFetchRate;
done();
}, 4500);
}, 500);
});

debuglet.start();
});

describe('map subtract', function() {
it('should be correct', function() {
var a = { a: 1, b: 2 };
Expand Down

0 comments on commit 66e5786

Please sign in to comment.