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 http-server-keep-alive-timeout #20093

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
49 changes: 24 additions & 25 deletions test/parallel/test-http-server-keep-alive-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,28 @@ function run() {
if (fn) fn(run);
}

test(function serverEndKeepAliveTimeoutWithPipeline(cb) {
function done(server, socket, cb) {
socket.destroy();
server.close(cb);
}

function serverTest(with_pipeline, cb) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: there are still a couple of snake case variables. Would you mind fixing those before of when landing? Thanks.

let got_all = false;
let timedout = false;
const server = http.createServer(common.mustCall((req, res) => {
res.end();
if (with_pipeline)
res.end();
if (req.url === '/3') {
got_all = true;
if (timedout)
done(server, req.socket, cb);
}
}, 3));
server.setTimeout(500, common.mustCall((socket) => {
server.setTimeout(500, common.mustCallAtLeast((socket) => {
// End this test and call `run()` for the next test (if any).
socket.destroy();
server.close();
cb();
timedout = true;
if (got_all)
done(server, socket, cb);
}));
server.keepAliveTimeout = 50;
server.listen(0, common.mustCall(() => {
Expand All @@ -40,26 +53,12 @@ test(function serverEndKeepAliveTimeoutWithPipeline(cb) {
c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n');
});
}));
}

test(function serverEndKeepAliveTimeoutWithPipeline(cb) {
serverTest(true, cb);
});

test(function serverNoEndKeepAliveTimeoutWithPipeline(cb) {
const server = http.createServer(common.mustCall(3));
server.setTimeout(500, common.mustCall((socket) => {
// End this test and call `run()` for the next test (if any).
socket.destroy();
server.close();
cb();
}));
server.keepAliveTimeout = 50;
server.listen(0, common.mustCall(() => {
const options = {
port: server.address().port,
allowHalfOpen: true
};
const c = net.connect(options, () => {
c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n');
c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n');
c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n');
});
}));
serverTest(false, cb);
});