2010-12-04 15:20:34 -08:00
|
|
|
var common = require('../common');
|
2010-12-06 01:33:52 +03:00
|
|
|
var assert = require('assert');
|
2010-12-04 15:20:34 -08:00
|
|
|
var http = require('http');
|
2015-05-13 21:25:57 -05:00
|
|
|
var net = require('net');
|
2010-05-12 10:01:27 -07:00
|
|
|
|
2010-12-06 01:33:52 +03:00
|
|
|
var server = http.createServer(function(req, res) {
|
2011-07-05 15:42:32 -07:00
|
|
|
console.log('got request. setting 1 second timeout');
|
2015-05-13 21:25:57 -05:00
|
|
|
var s = req.connection.setTimeout(500);
|
|
|
|
assert.ok(s instanceof net.Socket);
|
2011-10-15 01:08:36 +02:00
|
|
|
req.connection.on('timeout', function() {
|
2011-07-05 15:42:32 -07:00
|
|
|
req.connection.destroy();
|
2010-12-06 01:33:52 +03:00
|
|
|
common.debug('TIMEOUT');
|
2010-05-12 10:01:27 -07:00
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2010-12-06 01:33:52 +03:00
|
|
|
server.listen(common.PORT, function() {
|
|
|
|
console.log('Server running at http://127.0.0.1:' + common.PORT + '/');
|
2010-05-12 10:01:27 -07:00
|
|
|
|
2010-12-06 01:33:52 +03:00
|
|
|
var errorTimer = setTimeout(function() {
|
2013-06-12 23:51:17 +01:00
|
|
|
throw new Error('Timeout was not successful');
|
2010-05-12 10:01:27 -07:00
|
|
|
}, 2000);
|
|
|
|
|
2011-10-04 18:08:18 -04:00
|
|
|
var x = http.get({port: common.PORT, path: '/'});
|
|
|
|
x.on('error', function() {
|
2011-01-20 17:07:44 -08:00
|
|
|
clearTimeout(errorTimer);
|
|
|
|
console.log('HTTP REQUEST COMPLETE (this is good)');
|
2011-10-04 18:08:18 -04:00
|
|
|
});
|
2011-08-03 15:06:16 -07:00
|
|
|
x.end();
|
|
|
|
|
2010-05-12 10:01:27 -07:00
|
|
|
});
|