Skip to content

Instantly share code, notes, and snippets.

@s3u
Created June 22, 2012 15:13
Show Gist options
  • Save s3u/2973367 to your computer and use it in GitHub Desktop.
Save s3u/2973367 to your computer and use it in GitHub Desktop.
Another test for timeout
var http = require('http');
var options = {
host: 'localhost',
port: 3000,
method: 'HEAD',
headers: {
'connection': 'keep-alive'
},
path: '/'
};
var server = http.createServer(function (req, res) {
res.writeHead(204, {
'Connection': 'keep-alive'
});
res.end();
});
//options.agent = false;
var runs = 100;
var done = runs;
function down() {
done = done - 1;
console.log(done);
if(done <= 0) {
server.close();
}
}
server.listen(3000, function () {
for(var i = 0; i < runs; ++i) {
var req = http.request(options, function (res) {
down();
});
req.setTimeout(600, function () {
console.log('timed out');
down();
});
req.end();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment