Skip to content

Commit 797aa97

Browse files
committed
Fix test-debugger-client
1 parent 8d82ec2 commit 797aa97

2 files changed

Lines changed: 37 additions & 36 deletions

File tree

lib/_debugger.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,16 @@ exports.Client = Client;
131131

132132

133133
Client.prototype._onResponse = function(res) {
134-
console.error(res);
135134
for (var i = 0; i < this._reqCallbacks.length; i++) {
136135
var cb = this._reqCallbacks[i];
137136
if (this._reqCallbacks[i].request_seq == cb.request_seq) break;
138137
}
139138

140-
if (cb) {
139+
if (res.headers.Type == 'connect') {
140+
// do nothing
141+
} else if (cb) {
141142
this._reqCallbacks.splice(i, 1);
142143
cb(res.body);
143-
} else if (res.headers.Type == 'connect') {
144-
// do nothing
145144
} else {
146145
console.error("unhandled res: %j", res.body);
147146
}
Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
var common = require('../common');
22
var assert = require('assert');
3-
var d = require('_debugger');
3+
var debug = require('_debugger');
44

55
var spawn = require('child_process').spawn;
66

77

88
var resCount = 0;
9-
var p = new d.Protocol();
9+
var p = new debug.Protocol();
1010
p.onResponse = function (res) {
1111
resCount++;
1212
};
@@ -18,46 +18,48 @@ p.execute("Type: connect\r\n" +
1818
"Content-Length: 0\r\n\r\n");
1919
assert.equal(1, resCount);
2020

21-
var n = spawn(process.execPath,
22-
['-e', 'setInterval(function () { console.log("blah"); }, 1000);']);
2321

22+
var connectCount = 0;
2423

25-
var connected = false;
24+
function test(cb) {
25+
var nodeProcess = spawn(process.execPath,
26+
['-e', 'setInterval(function () { console.log("blah"); }, 1000);']);
2627

27-
n.stdout.once('data', function () {
28-
console.log("new node process: %d", n.pid);
29-
process.kill(n.pid, "SIGUSR1");
30-
console.log("signaling it with SIGUSR1");
31-
32-
});
28+
nodeProcess.stdout.once('data', function () {
29+
console.log("new node process: %d", nodeProcess.pid);
30+
process.kill(nodeProcess.pid, "SIGUSR1");
31+
console.log("signaling it with SIGUSR1");
32+
});
3333

34-
var didTryConnect = false;
35-
n.stderr.setEncoding('utf8');
36-
n.stderr.on('data', function (d) {
37-
if (didTryConnect == false && /debugger/.test(d)) {
38-
didTryConnect = true;
39-
tryConnect();
40-
}
41-
})
42-
43-
44-
function tryConnect() {
45-
// Wait for some data before trying to connect
46-
var c = new d.Client();
47-
process.stdout.write("connecting...");
48-
c.connect(d.port, function () {
49-
connected = true;
50-
console.log("connected!");
34+
var didTryConnect = false;
35+
nodeProcess.stderr.setEncoding('utf8');
36+
nodeProcess.stderr.on('data', function (data) {
37+
if (didTryConnect == false && /debugger/.test(data)) {
38+
didTryConnect = true;
39+
40+
// Wait for some data before trying to connect
41+
var c = new debug.Client();
42+
process.stdout.write("connecting...");
43+
c.connect(debug.port, function () {
44+
connectCount++;
45+
console.log("connected!");
46+
cb(c, nodeProcess);
47+
});
48+
}
5149
});
50+
}
5251

53-
c.reqVersion(function (v) {
52+
53+
test(function (client, nodeProcess) {
54+
client.reqVersion(function (v) {
55+
console.log("version: %s", v);
5456
assert.equal(process.versions.v8, v);
55-
n.kill();
57+
nodeProcess.kill();
5658
});
57-
}
59+
});
5860

5961

6062
process.on('exit', function() {
61-
assert.ok(connected);
63+
assert.equal(1, connectCount);
6264
});
6365

0 commit comments

Comments
 (0)