From 3b193defb2526ca0a3c11bde5a2f87e851c0c04e Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 24 Nov 2016 15:04:14 -0800 Subject: [PATCH] test: fix flaky test-cluster-dgram-2 There is no guarantee that a dgram packet will be received. The test is currently written to only send exactly as many dgram packets as required assuming they are all received. As a result, failures like this may occur (from CI): ``` not ok 719 parallel/test-cluster-dgram-2 --- duration_ms: 120.39 severity: fail stack: |- timeout ``` This change has the workers send packets continuously until disconnect. PR-URL: https://github.com/nodejs/node/pull/9791 Reviewed-By: Santiago Gimeno --- test/parallel/test-cluster-dgram-2.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-cluster-dgram-2.js b/test/parallel/test-cluster-dgram-2.js index 179b1ee15327e7..863e0fa358c73e 100644 --- a/test/parallel/test-cluster-dgram-2.js +++ b/test/parallel/test-cluster-dgram-2.js @@ -57,6 +57,13 @@ function worker() { // send(), explicitly bind them to an ephemeral port. socket.bind(0); - for (var i = 0; i < PACKETS_PER_WORKER; i++) + // There is no guarantee that a sent dgram packet will be received so keep + // sending until disconnect. + const interval = setInterval(() => { socket.send(buf, 0, buf.length, common.PORT, '127.0.0.1'); + }, 1); + + cluster.worker.on('disconnect', () => { + clearInterval(interval); + }); }