From 66369d05a2ad29b567c91094f1fb70114bed4de1 Mon Sep 17 00:00:00 2001 From: Ilkka Myller Date: Thu, 22 Sep 2016 00:49:47 +0300 Subject: [PATCH] test: fix test-cluster-worker-init.js flakyness Update test to match current test guidelines and use common.mustCall instead of unref'd timer. PR-URL: https://github.com/nodejs/node/pull/8703 Fixes: https://github.com/nodejs/node/issues/8700 Reviewed-By: Colin Ihrig Reviewed-By: Rich Trott Reviewed-By: Santiago Gimeno --- test/parallel/test-cluster-worker-init.js | 25 +++++++++-------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/test/parallel/test-cluster-worker-init.js b/test/parallel/test-cluster-worker-init.js index 41f73e1255a7c5..3b82866d1b14eb 100644 --- a/test/parallel/test-cluster-worker-init.js +++ b/test/parallel/test-cluster-worker-init.js @@ -3,30 +3,25 @@ // verifies that, when a child process is forked, the cluster.worker // object can receive messages as expected -require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); -var msg = 'foo'; +const common = require('../common'); +const assert = require('assert'); +const cluster = require('cluster'); +const msg = 'foo'; if (cluster.isMaster) { - var worker = cluster.fork(); - var timer = setTimeout(function() { - assert(false, 'message not received'); - }, 5000); + const worker = cluster.fork(); - timer.unref(); - - worker.on('message', function(message) { - assert(message, 'did not receive expected message'); + worker.on('message', common.mustCall((message) => { + assert.strictEqual(message, true, 'did not receive expected message'); worker.disconnect(); - }); + })); - worker.on('online', function() { + worker.on('online', () => { worker.send(msg); }); } else { // GH #7998 - cluster.worker.on('message', function(message) { + cluster.worker.on('message', (message) => { process.send(message === msg); }); }