Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the message pass to the assert module in Test cluster setup master #16065

Closed
wants to merge 5 commits into from
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions test/parallel/test-cluster-setup-master.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const cluster = require('cluster');

Expand All @@ -38,7 +38,7 @@ if (cluster.isWorker) {
};

const totalWorkers = 2;
let onlineWorkers = 0;
let settings;

// Setup master
cluster.setupMaster({
Expand All @@ -49,7 +49,7 @@ if (cluster.isWorker) {
cluster.once('setup', function() {
checks.setupEvent = true;

const settings = cluster.settings;
settings = cluster.settings;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change actually needed at all?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's to be able to stringify the "settings" variable inside the assert message.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BridgeAR Hey, just wanna be sure about "This effects the test subsystem and the commit message do not follow the guidelines that are linked when opening a PR. It would be nice if this could be fixed." you want me to rewrite each commit message to make sure they follow the guide line ?!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbeatj If you are comfortable with git, you can do a git rebase master -i and squash all the commits with one left as something like test: improve the assertion message

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbeatj Also you can leave this to whoever lands this and they would do that for you.

if (settings &&
settings.args && settings.args[0] === 'custom argument' &&
settings.silent === true &&
Expand All @@ -58,37 +58,34 @@ if (cluster.isWorker) {
}
});

let correctIn = 0;
let correctInput = 0;

cluster.on('online', function lisenter(worker) {

onlineWorkers++;
cluster.on('online', common.mustCall(function listener(worker) {

worker.once('message', function(data) {
correctIn += (data === 'custom argument' ? 1 : 0);
if (correctIn === totalWorkers) {
correctInput += (data === 'custom argument' ? 1 : 0);
if (correctInput === totalWorkers) {
checks.args = true;
}
worker.kill();
});

// All workers are online
if (onlineWorkers === totalWorkers) {
checks.workers = true;
}
});
}, totalWorkers));

// Start all workers
cluster.fork();
cluster.fork();

// Check all values
process.once('exit', function() {
assert.ok(checks.workers, 'Not all workers went online');
assert.ok(checks.args, 'The arguments was noy send to the worker');
const argsMsg = `The arguments was not send for one or more worker.
There was ${correctInput} worker that receive
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentations will be preserved when they show up in assertions. Can you change this to using concatenations instead?

argument, ${totalWorkers} were expected`;
assert.ok(checks.args, argsMsg);
assert.ok(checks.setupEvent, 'The setup event was never emitted');
const m = 'The settingsObject do not have correct properties';
assert.ok(checks.settingsObject, m);
const settingObjectMsg = `The settingsObject do not have correct
properties : ${JSON.stringify(settings)}`;
assert.ok(checks.settingsObject, settingObjectMsg);
});

}