node/test/parallel/test-cluster-worker-destroy.js
Gibson Fahnestock 7a0e462f9f test: use eslint to fix var->const/let
Manually fix issues that eslint --fix couldn't do automatically.

PR-URL: https://github.com/nodejs/node/pull/10685
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
2017-01-11 11:43:52 +00:00

37 lines
1.1 KiB
JavaScript

'use strict';
/*
* The goal of this test is to cover the Workers' implementation of
* Worker.prototype.destroy. Worker.prototype.destroy is called within
* the worker's context: once when the worker is still connected to the
* master, and another time when it's not connected to it, so that we cover
* both code paths.
*/
const common = require('../common');
const assert = require('assert');
const cluster = require('cluster');
let worker1, worker2;
if (cluster.isMaster) {
worker1 = cluster.fork();
worker2 = cluster.fork();
[worker1, worker2].forEach(function(worker) {
worker.on('disconnect', common.mustCall(function() {}));
worker.on('exit', common.mustCall(function() {}));
});
} else {
if (cluster.worker.id === 1) {
// Call destroy when worker is disconnected
cluster.worker.process.on('disconnect', function() {
cluster.worker.destroy();
});
const w = cluster.worker.disconnect();
assert.strictEqual(w, cluster.worker, 'did not return a reference');
} else {
// Call destroy when worker is not disconnected yet
cluster.worker.destroy();
}
}