Created
June 22, 2012 15:13
-
-
Save s3u/2973367 to your computer and use it in GitHub Desktop.
Another test for timeout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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