From b6fe731c55eb4cb9d14042a23e5002ed39b7c8b7 Mon Sep 17 00:00:00 2001 From: Arne Keller <2012gdwu+github@posteo.de> Date: Sun, 24 Nov 2024 23:30:38 +0100 Subject: [PATCH] test: make HTTP/1.0 connection test more robust Fixes: https://github.com/nodejs/node/issues/47200 Co-authored-by: Luigi Pinca PR-URL: https://github.com/nodejs/node/pull/55959 Reviewed-By: Luigi Pinca Reviewed-By: Yagiz Nizipli Reviewed-By: Jason Zhang --- ...emove-connection-header-persists-connection.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/test/parallel/test-http-remove-connection-header-persists-connection.js b/test/parallel/test-http-remove-connection-header-persists-connection.js index df7e39ae94375f..d5f53a703c821e 100644 --- a/test/parallel/test-http-remove-connection-header-persists-connection.js +++ b/test/parallel/test-http-remove-connection-header-persists-connection.js @@ -10,6 +10,13 @@ const server = http.createServer(function(request, response) { // For HTTP/1.0, the connection should be closed after the response automatically. response.removeHeader('connection'); + if (request.httpVersion === '1.0') { + const socket = request.socket; + response.on('finish', common.mustCall(function() { + assert.ok(socket.writableEnded); + })); + } + response.end('beep boop\n'); }); @@ -50,9 +57,7 @@ function makeHttp10Request(cb) { '\r\n'); socket.resume(); // Ignore the response itself - setTimeout(function() { - cb(socket); - }, common.platformTimeout(50)); + socket.on('close', cb); }); } @@ -62,9 +67,7 @@ server.listen(0, function() { // Both HTTP/1.1 requests should have used the same socket: assert.strictEqual(firstSocket, secondSocket); - makeHttp10Request(function(socket) { - // The server should have immediately closed the HTTP/1.0 socket: - assert.strictEqual(socket.closed, true); + makeHttp10Request(function() { server.close(); }); });