Skip to content

Commit

Permalink
test: fix test-net-settimeout flakiness
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
santigimeno authored and Myles Borins committed May 18, 2016
1 parent 69dcbb6 commit 37cc249
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions test/parallel/test-net-settimeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@ const assert = require('assert');

const T = 100;

const server = net.createServer(function(c) {
const server = net.createServer(common.mustCall((c) => {
c.write('hello');
});
}));

server.listen(common.PORT);

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

const s = socket.setTimeout(T, function() {
const s = socket.setTimeout(T, () => {
common.fail('Socket timeout event is not expected to fire');
});
assert.ok(s instanceof net.Socket);

socket.setTimeout(0);

setTimeout(function() {
socket.destroy();
server.close();
}, T * 2);
socket.on('data', common.mustCall(() => {
setTimeout(function() {
socket.destroy();
server.close();
}, T * 2);
}));

socket.setTimeout(0);

0 comments on commit 37cc249

Please sign in to comment.