From c7f54c6a93c07ddb4aed054fca49b3750c21880c Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Sun, 10 Sep 2023 21:21:13 +0200 Subject: [PATCH] test: add flaky test for investigation Refs: https://github.com/nodejs/node/pull/49574#issuecomment-1712776107 Refs: https://github.com/nodejs/node/pull/49574#issuecomment-1712846325 --- test/sequential/test-net-gh-49574.js | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/sequential/test-net-gh-49574.js diff --git a/test/sequential/test-net-gh-49574.js b/test/sequential/test-net-gh-49574.js new file mode 100644 index 00000000000000..73539cbcd3e9ce --- /dev/null +++ b/test/sequential/test-net-gh-49574.js @@ -0,0 +1,42 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); + +const COUNT = 1000 + 1; +let gotResponses = 0; + +const response = Buffer.from('HTTP/1.1 200 OK\r\n\r\n'); + +function execAndClose() { + process.stdout.write('.'); + + const chunks = []; + const socket = net.connect(common.PORT); + + socket.on('end', socket.end); + socket.on('connect', function() { + process.stdout.write('c'); + }); + socket.on('data', function(chunk) { + process.stdout.write('d'); + chunks.push(chunk); + }); + socket.on('close', function() { + assert.deepStrictEqual(Buffer.concat(chunks), response); + + if (++gotResponses === COUNT) { + server.close(); + } else { + execAndClose(); + } + }); +} + +const server = net.createServer(function(socket) { + socket.end(response); + socket.resume(); +}); + +server.listen(common.PORT, common.mustCall(execAndClose));