Remove excessive copyright/license boilerplate
[platform/upstream/nodejs.git] / test / pummel / test-http-upload-timeout.js
1 // This tests setTimeout() by having multiple clients connecting and sending
2 // data in random intervals. Clients are also randomly disconnecting until there
3 // are no more clients left. If no false timeout occurs, this test has passed.
4 var common = require('../common'),
5     assert = require('assert'),
6     http = require('http'),
7     server = http.createServer(),
8     connections = 0;
9
10 server.on('request', function(req, res) {
11   req.socket.setTimeout(1000);
12   req.socket.on('timeout', function() {
13     throw new Error('Unexpected timeout');
14   });
15   req.on('end', function() {
16     connections--;
17     res.writeHead(200);
18     res.end('done\n');
19     if (connections == 0) {
20       server.close();
21     }
22   });
23   req.resume();
24 });
25
26 server.listen(common.PORT, '127.0.0.1', function() {
27   for (var i = 0; i < 10; i++) {
28     connections++;
29
30     setTimeout(function() {
31       var request = http.request({
32         port: common.PORT,
33         method: 'POST',
34         path: '/'
35       });
36
37       function ping() {
38         var nextPing = (Math.random() * 900).toFixed();
39         if (nextPing > 600) {
40           request.end();
41           return;
42         }
43         request.write('ping');
44         setTimeout(ping, nextPing);
45       }
46       ping();
47     }, i * 50);
48   }
49 });