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

50 lines
1.0 KiB
JavaScript
Raw Normal View History

'use strict';
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);
client.on('error', function(err) {
2011-08-02 12:22:30 +08:00
// We should receive one error
console.log('ERROR! ' + err.message);
2010-08-11 08:37:30 +08:00
errorCount++;
});
client.on('end', function() {
2011-08-02 12:22:30 +08:00
// When we remove the old Client interface this will most likely have to be
// changed.
2010-12-03 09:03:18 +08:00
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.on('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);
process.on('exit', function() {
assert.equal(1, errorCount);
assert.equal(1, eofCount);
});