Skip to content

Commit 15c5da4

Browse files
committed
test: add flaky test for investigation
Refs: nodejs#49574 (comment) Refs: nodejs#49574 (comment)
1 parent b3fc917 commit 15c5da4

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const net = require('net');
6+
7+
const COUNT = 1000 + 1;
8+
let gotResponses = 0;
9+
10+
const response = Buffer.from('HTTP/1.1 200 OK\r\n\r\n');
11+
12+
function execAndClose() {
13+
process.stdout.write('.');
14+
15+
const chunks = [];
16+
const socket = net.connect(common.PORT);
17+
18+
socket.on('end', socket.end);
19+
socket.on('connect', function() {
20+
process.stdout.write('c');
21+
});
22+
socket.on('data', function(chunk) {
23+
process.stdout.write('d');
24+
chunks.push(chunk);
25+
});
26+
socket.on('close', function() {
27+
assert.deepStrictEqual(Buffer.concat(chunks), response);
28+
29+
if (++gotResponses === COUNT) {
30+
server.close();
31+
} else {
32+
execAndClose();
33+
}
34+
});
35+
}
36+
37+
const server = net.createServer(function(socket) {
38+
socket.end(response);
39+
socket.resume();
40+
});
41+
42+
server.listen(common.PORT, common.mustCall(execAndClose));

0 commit comments

Comments
 (0)