diff options
author | Felix Geisendörfer <felix@debuggable.com> | 2010-10-11 09:19:40 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-10-11 00:25:48 -0700 |
commit | 3cd09e7ba55b21586c338e177180449f22a5e56e (patch) | |
tree | 322fb6b4ea97ae7be8a25b5d1e13f8cbbc95ef26 /test/pummel/test-http-upload-timeout.js | |
parent | 1d3142a882d08a5cd1bf221cf37e76692bd71205 (diff) | |
download | node-new-3cd09e7ba55b21586c338e177180449f22a5e56e.tar.gz |
Stress test for http upload timeouts
This was meant to find a bug in setTimeout, but there doesn't seem to be
one. So this test can no help to prevent future regressions.
Diffstat (limited to 'test/pummel/test-http-upload-timeout.js')
-rw-r--r-- | test/pummel/test-http-upload-timeout.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/pummel/test-http-upload-timeout.js b/test/pummel/test-http-upload-timeout.js new file mode 100644 index 0000000000..e37b695325 --- /dev/null +++ b/test/pummel/test-http-upload-timeout.js @@ -0,0 +1,43 @@ +// This tests setTimeout() by having multiple clients connecting and sending +// data in random intervals. Clients are also randomly disconnecting until there +// are no more clients left. If no false timeout occurs, this test has passed. +var common = require("../common"), + assert = require("assert"), + http = require('http'), + server = http.createServer(), + connections = 0; + +server.on('request', function(req, res) { + req.socket.setTimeout(1000); + req.socket.on('timeout', function() { + throw new Error('Unexpected timeout'); + }); + req.on('end', function() { + connections--; + req.socket.end(); + if (connections == 0) { + server.close(); + } + }); +}); +server.listen(common.PORT, '127.0.0.1', function() { + for (var i = 0; i < 10; i++) { + connections++; + + setTimeout(function() { + var client = http.createClient(common.PORT, '127.0.0.1'), + request = client.request('POST', '/'); + + function ping() { + var nextPing = (Math.random() * 900).toFixed(); + if (nextPing > 600) { + request.end(); + return; + } + request.write('ping'); + setTimeout(ping, nextPing); + } + ping(); + }, i * 50); + } +}); |