Skip to content

Commit

Permalink
test: add flaky test for investigation
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Sep 10, 2023
1 parent b3fc917 commit c7f54c6
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/sequential/test-net-gh-49574.js
Original file line number Diff line number Diff line change
@@ -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));

0 comments on commit c7f54c6

Please sign in to comment.