Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
fixup! cluster: support windowsHide option for workers
  • Loading branch information
toddwong committed Dec 10, 2017
commit cc4081a758c308fb1e5b2c245a9b23c39f2d3e56
22 changes: 10 additions & 12 deletions test/parallel/test-cluster-fork-windowsHide.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@
const common = require('../common');
const assert = require('assert');
const child_process = require('child_process');

let patchedFork = child_process.fork;
child_process.fork = (...args) => patchedFork.apply(this, args);
const cluster = require('cluster');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can get rid of the monkey-patch now because ultimately it doesn't how matter how the option is passed down, as long as the observable effect is the same.

Presumably the child_process.spawn() call can go too? I admit I don't quite understand why you run the tests in a child process.

Copy link
Copy Markdown
Contributor Author

@toddwong toddwong Dec 3, 2017

Choose a reason for hiding this comment

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

I keep the monkey-patch just in case some one run the tests on other platforms or in a windows service session. Not sure if this is necessary or practically useful.

It seems Windows only allocate a new console window for an attaching process spawned by a detached process.

If process D is spawned by process C with detached: true , and process W is spawned by process D with detached: false, W will get a new black console window popped up.

if D is spawned by C with detached: false or W is spawned by D with detached: true, no console window will pop up for W.

C = Command, D = Daemon, W = worker, practically.

That's why the test need to be run in a (detached) child process.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@bnoordhuis Is this OK?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I keep the monkey-patch just in case some one run the tests on other platforms or in a windows service session. Not sure if this is necessary or practically useful.

Neither, I'd say. :-)

Can you add a comment to the test that explains why it spawns a child process first? I get it now from your explanation but it's not obvious from just looking at the code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, i'll add the comment, and remove the monkey-patch thing.


if (!process.argv[2]) {
/* It seems Windows only allocate new console window for
* attaching processes spawned by detached processes. i.e.
* - If process D is spawned by process C with `detached: true`,
* and process W is spawned by process D with `detached: false`,
* W will get a new black console window popped up.
* - If D is spawned by C with `detached: false` or W is spawned
* by D with `detached: true`, no console window will pop up for W.
*
* So, we have to spawn a detached process first to run the actual test.
*/
const master = child_process.spawn(
process.argv[0],
[process.argv[1], '--cluster'],
{ detached: true, stdio: ['ignore', 'ignore', 'ignore', 'ipc'] });

const messageHandlers = {
windowsHide: common.mustCall((msg) => {
assert.strictEqual(msg.value, true);
}),
workerOnline: common.mustCall((msg) => {
}),
mainWindowHandle: common.mustCall((msg) => {
Expand All @@ -40,12 +44,6 @@ if (!process.argv[2]) {
}));

} else if (cluster.isMaster) {
const originalFork = patchedFork;
patchedFork = common.mustCall((...args) => {
process.send({ type: 'windowsHide', value: args[2].windowsHide });
return originalFork.apply(this, args);
});

cluster.setupMaster({
silient: true,
windowsHide: true
Expand Down