From 68c32833c6891335232ab0ea03f73b6927d885bd Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Tue, 12 Apr 2016 17:22:07 +0200 Subject: [PATCH] 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 Reviewed-By: Benjamin Gruenbaum --- test/parallel/test-net-settimeout.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/test/parallel/test-net-settimeout.js b/test/parallel/test-net-settimeout.js index 76ed7b020fb89e..db0329deea0466 100644 --- a/test/parallel/test-net-settimeout.js +++ b/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);