From 26a5bd6a7f6a9a60a2d98c4422b92e0fadf05c67 Mon Sep 17 00:00:00 2001 From: Matt Loring Date: Thu, 21 Apr 2016 11:35:08 -0700 Subject: [PATCH] Update list breakpoint longpoll mechanism --- lib/debuglet.js | 10 +++++----- lib/debugletapi.js | 4 +--- test/standalone/test-debuglet.js | 14 ++++++++------ test/test-debugletapi.js | 21 +++++++++++---------- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/lib/debuglet.js b/lib/debuglet.js index b52e3bee..82fcdd97 100644 --- a/lib/debuglet.js +++ b/lib/debuglet.js @@ -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') { diff --git a/lib/debugletapi.js b/lib/debugletapi.js index 1e0dbbcf..aaf5c447 100644 --- a/lib/debugletapi.js +++ b/lib/debugletapi.js @@ -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. diff --git a/test/standalone/test-debuglet.js b/test/standalone/test-debuglet.js index 531a4c50..526cd9d7 100644 --- a/test/standalone/test-debuglet.js +++ b/test/standalone/test-debuglet.js @@ -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] }) @@ -202,7 +204,7 @@ describe(__filename, function(){ id: DEBUGGEE_ID } }) - .get(BPS_PATH) + .get(BPS_PATH + '?success_on_timeout=true') .reply(200, { breakpoints: [errorBp] }) @@ -239,7 +241,7 @@ describe(__filename, function(){ id: DEBUGGEE_ID } }) - .get(BPS_PATH) + .get(BPS_PATH + '?success_on_timeout=true') .reply(200, { breakpoints: [bp] }) diff --git a/test/test-debugletapi.js b/test/test-debugletapi.js index c7ba3c84..832c9131 100644 --- a/test/test-debugletapi.js +++ b/test/test-debugletapi.js @@ -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) { @@ -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'); @@ -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'); @@ -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(); }); @@ -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 });