Skip to content

Commit 4c48ec0

Browse files
lpincatargos
authored andcommitted
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: #59577 PR-URL: #59595 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent 3276bfa commit 4c48ec0

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

‎test/parallel/test-http-keep-alive-empty-line.mjs‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import assert from 'node:assert'
33
import{createServer}from'node:http';
44
import{connect}from'node:net';
55

6+
// This test ensures that data like an empty line (`\r\n`) recevied by the
7+
// server after a request, does not reset the keep-alive timeout. See
8+
// https://github.com/nodejs/node/issues/58140.
9+
610
constserver=createServer({
711
connectionsCheckingInterval: 100,
812
headersTimeout: 100,
@@ -28,23 +32,24 @@ server.listen(0, () =>{
2832
'\r\n'
2933
);
3034

31-
setTimeout(()=>{
32-
client.write('\r\n');
33-
},100);
34-
35-
letresponseBuffer='';
35+
letresponse='';
36+
letresponseReceived=false;
3637

38+
client.setEncoding('utf-8');
3739
client.on('data',(chunk)=>{
38-
responseBuffer+=chunk.toString();
40+
response+=chunk;
3941

4042
// Check if we've received the full header (ending with \r\n\r\n)
41-
if(responseBuffer.includes('\r\n\r\n')){
42-
conststatusLine=responseBuffer.split('\r\n')[0];
43+
if(response.includes('\r\n\r\n')){
44+
responseReceived=true;
45+
conststatusLine=response.split('\r\n')[0];
4346
conststatus=statusLine.split(' ')[1];
4447
assert.strictEqual(status,'404');
45-
client.end();
48+
client.write('\r\n');
4649
}
4750
});
48-
client.on('end',common.mustCall());
51+
client.on('end',common.mustCall(()=>{
52+
assert.ok(responseReceived);
53+
}));
4954
});
5055
});

0 commit comments

Comments
(0)