Skip to content

Commit 68c3283

Browse files
santigimenoMylesBorins
authored andcommitted
test: fix test-net-settimeout flakiness
Wait for the data to be received by the socket before creating the clean-up timer. This way, a possible (though unlikely) `ECONNRESET` error can be avoided. PR-URL: #6166 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent 85cb9bb commit 68c3283

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

test/parallel/test-net-settimeout.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,24 @@ const assert = require('assert');
88

99
const T = 100;
1010

11-
const server = net.createServer(function(c) {
11+
const server = net.createServer(common.mustCall((c) => {
1212
c.write('hello');
13-
});
13+
}));
14+
1415
server.listen(common.PORT);
1516

1617
const socket = net.createConnection(common.PORT, 'localhost');
1718

18-
const s = socket.setTimeout(T, function() {
19+
const s = socket.setTimeout(T, () => {
1920
common.fail('Socket timeout event is not expected to fire');
2021
});
2122
assert.ok(s instanceof net.Socket);
2223

23-
socket.setTimeout(0);
24-
25-
setTimeout(function() {
26-
socket.destroy();
27-
server.close();
28-
}, T * 2);
24+
socket.on('data', common.mustCall(() => {
25+
setTimeout(function() {
26+
socket.destroy();
27+
server.close();
28+
}, T * 2);
29+
}));
2930

31+
socket.setTimeout(0);

0 commit comments

Comments
 (0)