Browse Source

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: https://github.com/nodejs/node/pull/6166
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
v4.x
Santiago Gimeno 9 years ago
committed by Myles Borins
parent
commit
37cc249218
  1. 20
      test/parallel/test-net-settimeout.js

20
test/parallel/test-net-settimeout.js

@ -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);

Loading…
Cancel
Save