node/test/pummel/test-http-client-reconnect-...

46 lines
934 B
JavaScript
Raw Normal View History

2010-12-05 07:20:34 +08:00
var common = require('../common');
var assert = require('assert');
2010-12-03 09:03:18 +08:00
var net = require('net'),
util = require('util'),
http = require('http');
var errorCount = 0;
var eofCount = 0;
2010-08-11 08:37:30 +08:00
var server = net.createServer(function(socket) {
socket.end();
});
2010-12-03 09:03:18 +08:00
server.on('listening', function() {
2010-08-11 08:37:30 +08:00
var client = http.createClient(common.PORT);
2010-12-03 09:03:18 +08:00
client.addListener('error', function(err) {
console.log('ERROR! ' + err.message);
2010-08-11 08:37:30 +08:00
errorCount++;
});
2010-12-03 09:03:18 +08:00
client.addListener('end', function() {
console.log('EOF!');
2010-08-11 08:37:30 +08:00
eofCount++;
});
2010-12-03 09:03:18 +08:00
var request = client.request('GET', '/', {'host': 'localhost'});
2010-08-11 08:37:30 +08:00
request.end();
request.addListener('response', function(response) {
2010-12-03 09:03:18 +08:00
console.log('STATUS: ' + response.statusCode);
2010-08-11 08:37:30 +08:00
});
});
2010-08-11 08:37:30 +08:00
server.listen(common.PORT);
2010-12-03 09:03:18 +08:00
setTimeout(function() {
server.close();
}, 500);
2010-12-03 09:03:18 +08:00
process.addListener('exit', function() {
assert.equal(1, errorCount);
assert.equal(1, eofCount);
});