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

Commit 26a5bd6

Browse files
author
Matt Loring
committed
Update list breakpoint longpoll mechanism
1 parent 6cc78e6 commit 26a5bd6

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

lib/debuglet.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,13 @@ Debuglet.prototype.scheduleBreakpointFetch_ = function(seconds) {
210210
that.scheduleRegistration_(0 /*immediately*/);
211211
return;
212212

213-
case 409: // Timeout on a hanging GET.
214-
that.logger_.info('\t409 Long poll completed.');
215-
that.scheduleBreakpointFetch_(0/*immediately*/);
216-
return;
217-
218213
default:
219214
that.logger_.info('\t' + response.statusCode + ' completed.');
215+
if (body.wait_expired) {
216+
that.logger_.info('\tLong poll completed.');
217+
that.scheduleBreakpointFetch_(0/*immediately*/);
218+
return;
219+
}
220220
var bps = (body.breakpoints || []).filter(function(bp) {
221221
var action = bp.action || 'CAPTURE';
222222
if (action !== 'CAPTURE') {

lib/debugletapi.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,11 @@ DebugletApi.prototype.listBreakpoints = function(callback) {
209209
if (that.nextWaitToken_) {
210210
url += '?waitToken=' + encodeURIComponent(that.nextWaitToken_);
211211
}
212+
url += '?success_on_timeout=' + encodeURIComponent(true);
212213
that.request_({url: url, json: true}, function(err, response, body) {
213214
if (!response) {
214215
callback(err || new Error('unknown error - request response missing'));
215216
return;
216-
} else if (response.statusCode === 409) { // indicates end of a hanging GET
217-
callback(null, response);
218-
return;
219217
} else if (response.statusCode === 404) {
220218
// The v2 API returns 404 (google.rpc.Code.NOT_FOUND) when the agent
221219
// registration expires. We should re-register.

test/standalone/test-debuglet.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,13 @@ describe(__filename, function(){
158158
id: DEBUGGEE_ID
159159
}
160160
})
161-
.get(BPS_PATH)
161+
.get(BPS_PATH + '?success_on_timeout=true')
162162
.reply(404)
163-
.get(BPS_PATH)
164-
.reply(409)
165-
.get(BPS_PATH)
163+
.get(BPS_PATH + '?success_on_timeout=true')
164+
.reply(200, {
165+
wait_expired: true
166+
})
167+
.get(BPS_PATH + '?success_on_timeout=true')
166168
.reply(200, {
167169
breakpoints: [bp, logBp]
168170
})
@@ -202,7 +204,7 @@ describe(__filename, function(){
202204
id: DEBUGGEE_ID
203205
}
204206
})
205-
.get(BPS_PATH)
207+
.get(BPS_PATH + '?success_on_timeout=true')
206208
.reply(200, {
207209
breakpoints: [errorBp]
208210
})
@@ -239,7 +241,7 @@ describe(__filename, function(){
239241
id: DEBUGGEE_ID
240242
}
241243
})
242-
.get(BPS_PATH)
244+
.get(BPS_PATH + '?success_on_timeout=true')
243245
.reply(200, {
244246
breakpoints: [bp]
245247
})

test/test-debugletapi.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ describe('Debuglet API', function() {
141141

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

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

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

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

189191
debugletapi.listBreakpoints(function(err, response, result) {
190192
assert.ifError(err, 'not expecting an error');
191-
assert(!result, 'should not have a result');
192-
assert(response.statusCode === 409, 'should have the correct status code');
193+
assert(response.body.wait_expired, 'should have expired set');
193194
scope.done();
194195
done();
195196
});
@@ -203,7 +204,7 @@ describe('Debuglet API', function() {
203204
testsBreakpoints.forEach(function(breakpoints, index) {
204205
it('should pass test ' + index, function(done) {
205206
var scope = nock(url)
206-
.get(api + '/debuggees/fake-debuggee/breakpoints')
207+
.get(api + '/debuggees/fake-debuggee/breakpoints?success_on_timeout=true')
207208
.reply(200, {
208209
breakpoints: breakpoints
209210
});

0 commit comments

Comments
 (0)