mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
test: deflake test-http-keep-alive-empty-line
- Do not call `client.end()` to ensure that the socket is closed by the server. - Remove the timer and send the empty line when the response is received. Fixes: https://github.com/nodejs/node/issues/59577 PR-URL: https://github.com/nodejs/node/pull/59595 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
parent
42021e4b4c
commit
cc0cdb1ed1
|
|
@ -3,6 +3,10 @@ import assert from 'node:assert';
|
|||
import { createServer } from 'node:http';
|
||||
import { connect } from 'node:net';
|
||||
|
||||
// This test ensures that data like an empty line (`\r\n`) recevied by the
|
||||
// server after a request, does not reset the keep-alive timeout. See
|
||||
// https://github.com/nodejs/node/issues/58140.
|
||||
|
||||
const server = createServer({
|
||||
connectionsCheckingInterval: 100,
|
||||
headersTimeout: 100,
|
||||
|
|
@ -28,23 +32,24 @@ server.listen(0, () => {
|
|||
'\r\n'
|
||||
);
|
||||
|
||||
setTimeout(() => {
|
||||
client.write('\r\n');
|
||||
}, 100);
|
||||
|
||||
let responseBuffer = '';
|
||||
let response = '';
|
||||
let responseReceived = false;
|
||||
|
||||
client.setEncoding('utf-8');
|
||||
client.on('data', (chunk) => {
|
||||
responseBuffer += chunk.toString();
|
||||
response += chunk;
|
||||
|
||||
// Check if we've received the full header (ending with \r\n\r\n)
|
||||
if (responseBuffer.includes('\r\n\r\n')) {
|
||||
const statusLine = responseBuffer.split('\r\n')[0];
|
||||
if (response.includes('\r\n\r\n')) {
|
||||
responseReceived = true;
|
||||
const statusLine = response.split('\r\n')[0];
|
||||
const status = statusLine.split(' ')[1];
|
||||
assert.strictEqual(status, '404');
|
||||
client.end();
|
||||
client.write('\r\n');
|
||||
}
|
||||
});
|
||||
client.on('end', common.mustCall());
|
||||
client.on('end', common.mustCall(() => {
|
||||
assert.ok(responseReceived);
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user