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

Commit

Permalink
Update list breakpoint longpoll mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Loring committed Apr 22, 2016
1 parent 6cc78e6 commit 26a5bd6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
10 changes: 5 additions & 5 deletions lib/debuglet.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,13 @@ Debuglet.prototype.scheduleBreakpointFetch_ = function(seconds) {
that.scheduleRegistration_(0 /*immediately*/);
return;

case 409: // Timeout on a hanging GET.
that.logger_.info('\t409 Long poll completed.');
that.scheduleBreakpointFetch_(0/*immediately*/);
return;

default:
that.logger_.info('\t' + response.statusCode + ' completed.');
if (body.wait_expired) {
that.logger_.info('\tLong poll completed.');
that.scheduleBreakpointFetch_(0/*immediately*/);
return;
}
var bps = (body.breakpoints || []).filter(function(bp) {
var action = bp.action || 'CAPTURE';
if (action !== 'CAPTURE') {
Expand Down
4 changes: 1 addition & 3 deletions lib/debugletapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,11 @@ DebugletApi.prototype.listBreakpoints = function(callback) {
if (that.nextWaitToken_) {
url += '?waitToken=' + encodeURIComponent(that.nextWaitToken_);
}
url += '?success_on_timeout=' + encodeURIComponent(true);
that.request_({url: url, json: true}, function(err, response, body) {
if (!response) {
callback(err || new Error('unknown error - request response missing'));
return;
} else if (response.statusCode === 409) { // indicates end of a hanging GET
callback(null, response);
return;
} else if (response.statusCode === 404) {
// The v2 API returns 404 (google.rpc.Code.NOT_FOUND) when the agent
// registration expires. We should re-register.
Expand Down
14 changes: 8 additions & 6 deletions test/standalone/test-debuglet.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,13 @@ describe(__filename, function(){
id: DEBUGGEE_ID
}
})
.get(BPS_PATH)
.get(BPS_PATH + '?success_on_timeout=true')
.reply(404)
.get(BPS_PATH)
.reply(409)
.get(BPS_PATH)
.get(BPS_PATH + '?success_on_timeout=true')
.reply(200, {
wait_expired: true
})
.get(BPS_PATH + '?success_on_timeout=true')
.reply(200, {
breakpoints: [bp, logBp]
})
Expand Down Expand Up @@ -202,7 +204,7 @@ describe(__filename, function(){
id: DEBUGGEE_ID
}
})
.get(BPS_PATH)
.get(BPS_PATH + '?success_on_timeout=true')
.reply(200, {
breakpoints: [errorBp]
})
Expand Down Expand Up @@ -239,7 +241,7 @@ describe(__filename, function(){
id: DEBUGGEE_ID
}
})
.get(BPS_PATH)
.get(BPS_PATH + '?success_on_timeout=true')
.reply(200, {
breakpoints: [bp]
})
Expand Down
21 changes: 11 additions & 10 deletions test/test-debugletapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe('Debuglet API', function() {

it('should deal with a missing breakpoints response', function(done) {
var scope = nock(url)
.get(api + '/debuggees/fake-debuggee/breakpoints')
.get(api + '/debuggees/fake-debuggee/breakpoints?success_on_timeout=true')
.reply(200, { kind: 'whatever' });

debugletapi.listBreakpoints(function(err, response, result) {
Expand All @@ -157,8 +157,8 @@ describe('Debuglet API', function() {
tests.forEach(function(invalidResponse, index) {
it('should pass test ' + index, function(done) {
var scope = nock(url)
.get(api + '/debuggees/fake-debuggee/breakpoints')
.reply(200, invalidResponse);
.get(api + '/debuggees/fake-debuggee/breakpoints?success_on_timeout=true')
.reply(200, invalidResponse);
debugletapi.listBreakpoints(function(err, response, result) {
assert(!err, 'not expecting an error');
assert(!result.breakpoints, 'should not have breakpoints property');
Expand All @@ -171,8 +171,8 @@ describe('Debuglet API', function() {

it('should throw error on http errors', function(done) {
var scope = nock(url)
.get(api + '/debuggees/fake-debuggee/breakpoints')
.reply(403);
.get(api + '/debuggees/fake-debuggee/breakpoints?success_on_timeout=true')
.reply(403);
debugletapi.listBreakpoints(function(err, response, result) {
assert(err instanceof Error, 'expecting an error');
assert(!result, 'should not have a result');
Expand All @@ -183,13 +183,14 @@ describe('Debuglet API', function() {

it('should work with waitTokens', function(done) {
var scope = nock(url)
.get(api + '/debuggees/fake-debuggee/breakpoints')
.reply(409);
.get(api + '/debuggees/fake-debuggee/breakpoints?success_on_timeout=true')
.reply(200, {
wait_expired: true
});

debugletapi.listBreakpoints(function(err, response, result) {
assert.ifError(err, 'not expecting an error');
assert(!result, 'should not have a result');
assert(response.statusCode === 409, 'should have the correct status code');
assert(response.body.wait_expired, 'should have expired set');
scope.done();
done();
});
Expand All @@ -203,7 +204,7 @@ describe('Debuglet API', function() {
testsBreakpoints.forEach(function(breakpoints, index) {
it('should pass test ' + index, function(done) {
var scope = nock(url)
.get(api + '/debuggees/fake-debuggee/breakpoints')
.get(api + '/debuggees/fake-debuggee/breakpoints?success_on_timeout=true')
.reply(200, {
breakpoints: breakpoints
});
Expand Down

0 comments on commit 26a5bd6

Please sign in to comment.