Skip to content

Commit

Permalink
test: fix flaky test-http-agent-keepalive
Browse files Browse the repository at this point in the history
Remove timeout delay causing flakiness on SmartOS.

Fixes: #4492
PR-URL: #4524
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rod Vagg <[email protected]>
Reviewed-By: Johan Bergström <[email protected]>
  • Loading branch information
Trott authored and Myles Borins committed Jan 19, 2016
1 parent 25c41d0 commit 7caf87b
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions test/parallel/test-http-agent-keepalive.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var http = require('http');
var Agent = require('_http_agent').Agent;
var EventEmitter = require('events').EventEmitter;
const common = require('../common');
const assert = require('assert');
const http = require('http');
const Agent = require('_http_agent').Agent;
const EventEmitter = require('events').EventEmitter;

var agent = new Agent({
const agent = new Agent({
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: 5,
maxFreeSockets: 5
});

var server = http.createServer(function(req, res) {
const server = http.createServer(function(req, res) {
if (req.url === '/error') {
res.destroy();
return;
} else if (req.url === '/remote_close') {
// cache the socket, close it after 100ms
var socket = res.connection;
setTimeout(function() {
// cache the socket, close it after a short delay
const socket = res.connection;
setImmediate(function() {
socket.end();
}, 100);
});
}
res.end('hello world');
});
Expand All @@ -35,7 +35,7 @@ function get(path, callback) {
}, callback);
}

var name = 'localhost:' + common.PORT + ':';
const name = 'localhost:' + common.PORT + ':';

function checkDataAndSockets(body) {
assert.equal(body.toString(), 'hello world');
Expand Down Expand Up @@ -77,15 +77,15 @@ function remoteClose() {
assert.equal(agent.freeSockets[name], undefined,
'freeSockets is not empty');
remoteError();
}, 200);
}, common.platformTimeout(200));
});
});
});
}

function remoteError() {
// remove server will destroy ths socket
var req = get('/error', function(res) {
const req = get('/error', function(res) {
throw new Error('should not call this function');
});
req.on('error', function(err) {
Expand All @@ -98,7 +98,7 @@ function remoteError() {
assert.equal(agent.sockets[name], undefined);
assert.equal(agent.freeSockets[name], undefined);
done();
}, 1);
}, common.platformTimeout(1));
});
}

Expand Down

0 comments on commit 7caf87b

Please sign in to comment.