Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix flaky test-http-agent-keepalive #4524

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
test: fix flaky test-http-agent-keepalive
Remove timeout delay causing flakiness on SmartOS.

Fixes: #4492
  • Loading branch information
Trott committed Jan 4, 2016
commit 324d4604623204765accd0463f6a1787284d926d
28 changes: 14 additions & 14 deletions test/parallel/test-http-agent-keepalive.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var http = require('http');
var Agent = require('_http_agent').Agent;
const common = require('../common');
const assert = require('assert');
const http = require('http');
const Agent = require('_http_agent').Agent;

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 @@ -34,7 +34,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 @@ -76,15 +76,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 @@ -97,7 +97,7 @@ function remoteError() {
assert.equal(agent.sockets[name], undefined);
assert.equal(agent.freeSockets[name], undefined);
done();
}, 1);
}, common.platformTimeout(1));
});
}

Expand Down