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

Commit

Permalink
test updates for streams2
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Dec 15, 2012
1 parent 0977638 commit 19ecc3a
Show file tree
Hide file tree
Showing 21 changed files with 43 additions and 17 deletions.
11 changes: 3 additions & 8 deletions test/simple/test-domain-http-server.js
Expand Up @@ -39,7 +39,7 @@ var server = http.createServer(function(req, res) {

dom.on('error', function(er) {
serverCaught++;
console.log('server error', er);
console.log('horray! got a server error', er);
// try to send a 500. If that fails, oh well.
res.writeHead(500, {'content-type':'text/plain'});
res.end(er.stack || er.message || 'Unknown error');
Expand Down Expand Up @@ -82,12 +82,7 @@ function next() {
dom.on('error', function(er) {
clientCaught++;
console.log('client error', er);
// kill everything.
dom.dispose();
});

dom.on('dispose', function() {
disposeEmit += 1;
req.socket.destroy();
});

var req = http.get({ host: 'localhost', port: common.PORT, path: p });
Expand All @@ -107,6 +102,7 @@ function next() {
d += c;
});
res.on('end', function() {
console.error('trying to parse json', d);
d = JSON.parse(d);
console.log('json!', d);
});
Expand All @@ -117,6 +113,5 @@ function next() {
process.on('exit', function() {
assert.equal(serverCaught, 2);
assert.equal(clientCaught, 2);
assert.equal(disposeEmit, 2);
console.log('ok');
});
10 changes: 7 additions & 3 deletions test/simple/test-http-agent.js
Expand Up @@ -40,10 +40,14 @@ server.listen(common.PORT, function() {
setTimeout(function() {
for (var j = 0; j < M; j++) {
http.get({ port: common.PORT, path: '/' }, function(res) {
console.log(res.statusCode);
if (++responses == N * M) server.close();
console.log('%d %d', responses, res.statusCode);
if (++responses == N * M) {
console.error('Received all responses, closing server');
server.close();
}
res.resume();
}).on('error', function(e) {
console.log(e.message);
console.log('Error!', e);
process.exit(1);
});
}
Expand Down
1 change: 1 addition & 0 deletions test/simple/test-http-date-header.js
Expand Up @@ -49,6 +49,7 @@ server.addListener('listening', function() {
server.close();
process.exit();
});
res.resume();
});
req.end();
});
1 change: 1 addition & 0 deletions test/simple/test-http-default-encoding.js
Expand Up @@ -50,6 +50,7 @@ server.listen(common.PORT, function() {
method: 'POST'
}, function(res) {
console.log(res.statusCode);
res.resume();
}).on('error', function(e) {
console.log(e.message);
process.exit(1);
Expand Down
1 change: 1 addition & 0 deletions test/simple/test-http-header-read.js
Expand Up @@ -50,5 +50,6 @@ function runTest() {
response.on('end', function() {
s.close();
});
response.resume();
});
}
6 changes: 4 additions & 2 deletions test/simple/test-http-host-headers.js
Expand Up @@ -57,13 +57,14 @@ function testHttp() {

var counter = 0;

function cb() {
function cb(res) {
counter--;
console.log('back from http request. counter = ' + counter);
if (counter === 0) {
httpServer.close();
testHttps();
}
res.resume();
}

httpServer.listen(common.PORT, function(er) {
Expand Down Expand Up @@ -124,13 +125,14 @@ function testHttps() {

var counter = 0;

function cb() {
function cb(res) {
counter--;
console.log('back from https request. counter = ' + counter);
if (counter === 0) {
httpsServer.close();
console.log('ok');
}
res.resume();
}

httpsServer.listen(common.PORT, function(er) {
Expand Down
7 changes: 5 additions & 2 deletions test/simple/test-http-keep-alive-close-on-header.js
Expand Up @@ -44,8 +44,9 @@ server.listen(common.PORT, function() {
headers: headers,
port: common.PORT,
agent: agent
}, function() {
}, function(res) {
assert.equal(1, agent.sockets['localhost:' + common.PORT].length);
res.resume();
});
request.on('socket', function(s) {
s.on('connect', function() {
Expand All @@ -60,8 +61,9 @@ server.listen(common.PORT, function() {
headers: headers,
port: common.PORT,
agent: agent
}, function() {
}, function(res) {
assert.equal(1, agent.sockets['localhost:' + common.PORT].length);
res.resume();
});
request.on('socket', function(s) {
s.on('connect', function() {
Expand All @@ -80,6 +82,7 @@ server.listen(common.PORT, function() {
assert.equal(1, agent.sockets['localhost:' + common.PORT].length);
server.close();
});
response.resume();
});
request.on('socket', function(s) {
s.on('connect', function() {
Expand Down
3 changes: 3 additions & 0 deletions test/simple/test-http-keep-alive.js
Expand Up @@ -42,13 +42,15 @@ server.listen(common.PORT, function() {
}, function(response) {
assert.equal(agent.sockets[name].length, 1);
assert.equal(agent.requests[name].length, 2);
response.resume();
});

http.get({
path: '/', headers: headers, port: common.PORT, agent: agent
}, function(response) {
assert.equal(agent.sockets[name].length, 1);
assert.equal(agent.requests[name].length, 1);
response.resume();
});

http.get({
Expand All @@ -59,6 +61,7 @@ server.listen(common.PORT, function() {
assert(!agent.requests.hasOwnProperty(name));
server.close();
});
response.resume();
});
});

Expand Down
1 change: 1 addition & 0 deletions test/simple/test-http-many-keep-alive-connections.js
Expand Up @@ -55,6 +55,7 @@ server.listen(common.PORT, function() {
server.close();
}
});
res.resume();
}).on('error', function(e) {
console.log(e.message);
process.exit(1);
Expand Down
1 change: 1 addition & 0 deletions test/simple/test-http-parser-free.js
Expand Up @@ -44,6 +44,7 @@ server.listen(common.PORT, function() {
if (++responses === N) {
server.close();
}
res.resume();
});
})(i);
}
Expand Down
1 change: 1 addition & 0 deletions test/simple/test-http-request-end-twice.js
Expand Up @@ -36,6 +36,7 @@ server.listen(common.PORT, function() {
assert.ok(!req.end());
server.close();
});
res.resume();
});
});

1 change: 1 addition & 0 deletions test/simple/test-http-request-end.js
Expand Up @@ -47,6 +47,7 @@ server.listen(common.PORT, function() {
method: 'POST'
}, function(res) {
console.log(res.statusCode);
res.resume();
}).on('error', function(e) {
console.log(e.message);
process.exit(1);
Expand Down
6 changes: 4 additions & 2 deletions test/simple/test-http-res-write-end-dont-take-array.js
Expand Up @@ -53,11 +53,13 @@ var server = http.createServer(function(req, res) {

server.listen(common.PORT, function() {
// just make a request, other tests handle responses
http.get({port: common.PORT}, function() {
http.get({port: common.PORT}, function(res) {
res.resume();
// lazy serial test, becuase we can only call end once per request
test += 1;
// do it again to test .end(Buffer);
http.get({port: common.PORT}, function() {
http.get({port: common.PORT}, function(res) {
res.resume();
server.close();
});
});
Expand Down
1 change: 1 addition & 0 deletions test/simple/test-http-response-readable.js
Expand Up @@ -35,6 +35,7 @@ testServer.listen(common.PORT, function() {
assert.equal(res.readable, false, 'res.readable set to false after end');
testServer.close();
});
res.resume();
});
});

1 change: 1 addition & 0 deletions test/simple/test-http-set-trailers.js
Expand Up @@ -106,6 +106,7 @@ server.on('listening', function() {
process.exit();
}
});
res.resume();
});
outstanding_reqs++;
});
1 change: 1 addition & 0 deletions test/simple/test-http-status-code.js
Expand Up @@ -59,6 +59,7 @@ function nextTest() {
testIdx += 1;
nextTest();
});
response.resume();
});
}

Expand Down
2 changes: 2 additions & 0 deletions test/simple/test-http-timeout.js
Expand Up @@ -55,6 +55,8 @@ server.listen(port, function() {
server.close();
}
})

res.resume();
});

req.setTimeout(1000, callback);
Expand Down
1 change: 1 addition & 0 deletions test/simple/test-https-agent.js
Expand Up @@ -54,6 +54,7 @@ server.listen(common.PORT, function() {
port: common.PORT,
rejectUnauthorized: false
}, function(res) {
res.resume();
console.log(res.statusCode);
if (++responses == N * M) server.close();
}).on('error', function(e) {
Expand Down
2 changes: 2 additions & 0 deletions test/simple/test-https-socket-options.js
Expand Up @@ -55,6 +55,7 @@ server_http.listen(common.PORT, function() {
rejectUnauthorized: false
}, function(res) {
server_http.close();
res.resume();
});
// These methods should exist on the request and get passed down to the socket
req.setNoDelay(true);
Expand All @@ -77,6 +78,7 @@ server_https.listen(common.PORT+1, function() {
rejectUnauthorized: false
}, function(res) {
server_https.close();
res.resume();
});
// These methods should exist on the request and get passed down to the socket
req.setNoDelay(true);
Expand Down
1 change: 1 addition & 0 deletions test/simple/test-https-strict.js
Expand Up @@ -170,6 +170,7 @@ function makeReq(path, port, error, host, ca) {
server2.close();
server3.close();
}
res.resume();
})
}

Expand Down
1 change: 1 addition & 0 deletions test/simple/test-regress-GH-877.js
Expand Up @@ -48,6 +48,7 @@ server.listen(common.PORT, '127.0.0.1', function() {
if (++responses == N) {
server.close();
}
res.resume();
});

assert.equal(req.agent, agent);
Expand Down

0 comments on commit 19ecc3a

Please sign in to comment.