test: refactor functions to es6

PR-URL: https://github.com/nodejs/node/pull/23510
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
Michael Chen 2018-10-12 10:22:52 -07:00 committed by Ruben Bridgewater
parent 3b477224a4
commit 3d8c512b67
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762

View File

@ -30,14 +30,12 @@ assert(cluster.isMaster);
// makes that unnecessary. This is to make the test less fragile if the // makes that unnecessary. This is to make the test less fragile if the
// implementation ever changes such that cluster.settings is mutated instead of // implementation ever changes such that cluster.settings is mutated instead of
// replaced. // replaced.
function cheapClone(obj) { const cheapClone = (obj) => JSON.parse(JSON.stringify(obj));
return JSON.parse(JSON.stringify(obj));
}
const configs = []; const configs = [];
// Capture changes // Capture changes
cluster.on('setup', function() { cluster.on('setup', () => {
console.log('"setup" emitted', cluster.settings); console.log('"setup" emitted', cluster.settings);
configs.push(cheapClone(cluster.settings)); configs.push(cheapClone(cluster.settings));
}); });
@ -48,7 +46,7 @@ const execs = [
'node-next-3', 'node-next-3',
]; ];
process.on('exit', function assertTests() { process.on('exit', () => {
// Tests that "setup" is emitted for every call to setupMaster // Tests that "setup" is emitted for every call to setupMaster
assert.strictEqual(configs.length, execs.length); assert.strictEqual(configs.length, execs.length);
@ -58,14 +56,14 @@ process.on('exit', function assertTests() {
}); });
// Make changes to cluster settings // Make changes to cluster settings
execs.forEach(function(v, i) { execs.forEach((v, i) => {
setTimeout(function() { setTimeout(() => {
cluster.setupMaster({ exec: v }); cluster.setupMaster({ exec: v });
}, i * 100); }, i * 100);
}); });
// cluster emits 'setup' asynchronously, so we must stay alive long // cluster emits 'setup' asynchronously, so we must stay alive long
// enough for that to happen // enough for that to happen
setTimeout(function() { setTimeout(() => {
console.log('cluster setup complete'); console.log('cluster setup complete');
}, (execs.length + 1) * 100); }, (execs.length + 1) * 100);