Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

test: fix failing due to too early timeout

  • Loading branch information...
commit a1ba29d110faf53ad7eb579a523a507ed28874bf 1 parent 5691e8a
@shigeki shigeki authored bnoordhuis committed
Showing with 15 additions and 6 deletions.
  1. +15 −6 test/simple/test-http-client-timeout-agent.js
View
21 test/simple/test-http-client-timeout-agent.js
@@ -23,13 +23,15 @@ var common = require('../common');
var assert = require('assert');
var http = require('http');
+var timeout = 15*1000;
+var max_requests = 30;
var request_number = 0;
var requests_sent = 0;
var requests_done = 0;
var options = {
method: 'GET',
port: common.PORT,
- host: '127.0.0.1',
+ host: '127.0.0.1'
};
//http.globalAgent.maxSockets = 15;
@@ -50,7 +52,9 @@ var server = http.createServer(function(req, res) {
server.listen(options.port, options.host, function() {
var req;
- for (requests_sent = 0; requests_sent < 30; requests_sent+=1) {
+ for (requests_sent = 0; requests_sent < max_requests;
+ requests_sent++) {
+
options.path = '/' + requests_sent;
req = http.request(options);
req.id = requests_sent;
@@ -60,7 +64,7 @@ server.listen(options.port, options.host, function() {
});
res.on('end', function(data) {
console.log('res#'+this.req.id+' end');
- requests_done += 1;
+ if (++requests_done === max_requests) finish();
});
});
req.on('close', function() {
@@ -74,13 +78,18 @@ server.listen(options.port, options.host, function() {
var req = this;
console.log('req#'+this.id + ' timeout');
req.abort();
- requests_done += 1;
+ if (++requests_done === max_requests) finish();
});
req.end();
}
- setTimeout(function() {
+ var tid = setTimeout(function() {
+ finish();
+ }, timeout);
+
+ function finish() {
+ clearTimeout(tid);
server.close();
- }, 150);
+ }
});
process.on('exit', function() {
Please sign in to comment.
Something went wrong with that request. Please try again.