From 294bcb33e6dc2d774deb4d6edbde2c1584e7bc20 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 30 Dec 2010 17:33:06 -0800 Subject: [PATCH] debugger: Fix some parser issues Wouldn't handle events if it got backed up. --- lib/_debugger.js | 1 + test/simple/test-debugger-client.js | 49 +++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/lib/_debugger.js b/lib/_debugger.js index 4f95293a44..98e19be131 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -43,6 +43,7 @@ Protocol.prototype._newRes = function(raw) { this.res = { raw: raw || '', headers: {} }; this.state = 'headers'; this.reqSeq = 1; + this.execute(''); }; diff --git a/test/simple/test-debugger-client.js b/test/simple/test-debugger-client.js index c542f89c49..9708e70da4 100644 --- a/test/simple/test-debugger-client.js +++ b/test/simple/test-debugger-client.js @@ -18,6 +18,55 @@ p.execute("Type: connect\r\n" + "Content-Length: 0\r\n\r\n"); assert.equal(1, resCount); +// Make sure split messages go in. + +var parts = []; +parts.push('Content-Length: 336\r\n'); +assert.equal(21, parts[0].length); +parts.push('\r\n'); +assert.equal(2, parts[1].length); +var bodyLength = 0; + +parts.push('{"seq":12,"type":"event","event":"break","body":' + + '{"invocationText":"#'); +assert.equal(78, parts[2].length); +bodyLength += parts[2].length; + +parts.push('.[anonymous](req=#, res=#)",' + + '"sourceLine"'); +assert.equal(78, parts[3].length); +bodyLength += parts[3].length; + +parts.push(':45,"sourceColumn":4,"sourceLineText":" debugger;","script":' + + '{"id":24,"name":"/home/ryan/projects/node/benchmark/http_simple.js",' + + '"lineOffset":0,"columnOffset":0,"lineCount":98}}}'); +assert.equal(180, parts[4].length); +bodyLength += parts[4].length; + +assert.equal(336, bodyLength); + +for (var i = 0; i < parts.length; i++) { + p.execute(parts[i]); +} +assert.equal(2, resCount); + + +// Make sure that if we get backed up, we still manage to get all the +// messages +var d = 'Content-Length: 466\r\n\r\n' + + '{"seq":10,"type":"event","event":"afterCompile","success":true,' + + '"body":{"script":{"handle":1,"type":"script","name":"dns.js",' + + '"id":34,"lineOffset":0,"columnOffset":0,"lineCount":241,"sourceStart":' + + '"(function (module, exports, require) {var dns = process.binding(\'cares\')' + + ';\\nvar ne","sourceLength":6137,"scriptType":2,"compilationType":0,' + + '"context":{"ref":0},"text":"dns.js (lines: 241)"}},"refs":[{"handle":0' + + ',"type":"context","text":"#"}],"running":true}' + + 'Content-Length: 119\r\n\r\n' + + '{"seq":11,"type":"event","event":"scriptCollected","success":true,' + + '"body":{"script":{"id":26}},"refs":[],"running":true}'; +p.execute(d); +assert.equal(4, resCount); + var expectedConnections = 0; var tests = []; function addTest (cb) {