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

feat: add worker count env variable to processes #3821

Merged
merged 10 commits into from
Oct 30, 2022

Conversation

ariba-05
Copy link
Contributor

Fixes #3231

Copy link
Member

@nicojs nicojs left a comment

Choose a reason for hiding this comment

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

This is great stuff! Got some remarks.

Comment on lines 2 to 8
private childId: number;
constructor() {
this.childId = 0;
}
public next(): number {
return this.childId++;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private childId: number;
constructor() {
this.childId = 0;
}
public next(): number {
return this.childId++;
}
private id = 0;
public next(): number {
return this.id++;
}

@@ -58,6 +60,7 @@ export class MutantInstrumenterExecutor {

const checkerPoolProvider = concurrencyTokenProviderProvider
.provideValue(coreTokens.checkerConcurrencyTokens, concurrencyTokenProvider.checkerToken$)
.provideClass('worker-id-generator', IdGenerator)
Copy link
Member

Choose a reason for hiding this comment

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

We should add the 'worker-id-generator' to the coreTokens, as we've done with the others.


beforeEach(() => {
childProcessProxyCreateStub = sinon.stub(ChildProcessProxy, 'create');
loggingContext = { port: 4200, level: LogLevel.Fatal };
fileDescriptions = { 'foo.js': { mutate: true } };
idGenerator = new IdGenerator();
Copy link
Member

Choose a reason for hiding this comment

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

This is a unit test, so it's better not to depend on the implementation of IdGenerator. That way we can change the implementation details later without breaking the tests.

Something like this:

let idGeneratorMock: sinon.SinonStubbedInstance<IdGenerator>;

// in before each:

idGeneratorMock = sinon.createStubInstance(IdGenerator);

// In your test where you verify that the worker id is passed correctly:
idGeneratorMock.next.returns(42);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made similar changes in child-process-proxy.spec.ts. Could you pls review if I've done it correctly as you suggested?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that is good 👌

Comment on lines 96 to 102
expect(logMock.debug).calledWith(
'Started %s in child process %s%s & env var STRYKER_MUTATOR_WORKER as %s',
'HelloClass',
childProcessMock.pid,
' (using args --cpu-prof --inspect)',
nextWorkerId
);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
expect(logMock.debug).calledWith(
'Started %s in child process %s%s & env var STRYKER_MUTATOR_WORKER as %s',
'HelloClass',
childProcessMock.pid,
' (using args --cpu-prof --inspect)',
nextWorkerId
);
expect(logMock.debug).calledWith(
'Started %s in worker process %s with pid %s %s',
'HelloClass',
nextWorkerId,
childProcessMock.pid,
' (using args --cpu-prof --inspect)'
);

I think this is cleaner :)

this.worker = childProcess.fork(fileURLToPath(new URL('./child-process-proxy-worker.js', import.meta.url)), {
silent: true,
execArgv,
env: { STRYKER_MUTATOR_WORKER: workerId },
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
env: { STRYKER_MUTATOR_WORKER: workerId },
env: { STRYKER_MUTATOR_WORKER: workerId, ...process.env },

We shouldn't forget to also pass along the process.env of the parent process.

@ariba-05
Copy link
Contributor Author

ariba-05 commented Oct 30, 2022

I can't seem to find the root cause of time out error in the CI e2e tests (https://github.com/stryker-mutator/stryker-js/actions/runs/3351682875/jobs/5553525949)9). The e2e test errors I get in my local setup are different. I've pushed everything else. @nicojs , could you please maybe trigger the workflow again to see if the errors are the same now? :/

@ariba-05 ariba-05 changed the title Mutant Worker Id feat: add worker count env variable to processes Oct 30, 2022
@@ -20,15 +22,17 @@ createTestRunnerFactory.inject = tokens(
coreTokens.sandbox,
coreTokens.loggingContext,
commonTokens.getLogger,
coreTokens.pluginModulePaths
coreTokens.pluginModulePaths,
'worker-id-generator'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
'worker-id-generator'
coreTokens.workerIdGenerator

beforeEach(() => {
idGenerator = new IdGenerator();
});
it('should increment workerId on calling `next`', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

Since we control the SUT (System Under Test, namely the IdGenerator class), we can test that the first call to next provides the value 0.

Copy link
Member

@nicojs nicojs left a comment

Choose a reason for hiding this comment

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

Wow, this looks great! You did a great job. Just 2 nit remarks. I'll merge it later tonight if you don't have time to fix them 👍.

@ariba-05
Copy link
Contributor Author

Made the changes, @nicojs. Thanks for the review and helping me through my first open source contribution 😄

Copy link
Member

@nicojs nicojs left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@nicojs nicojs merged commit efb6fd6 into stryker-mutator:master Oct 30, 2022
@nicojs
Copy link
Member

nicojs commented Oct 30, 2022

I've released this feature in 6.3 🎉
https://github.com/stryker-mutator/stryker-js/releases/tag/v6.3.0

This feature still needs documentation. I've opened #3828 for it. Feel free to pick it up if you want 😉

@nicojs
Copy link
Member

nicojs commented Oct 30, 2022

Thanks for the review and helping me through my first open source contribution 😄

The first of many, I hope 🤝. My pleasure; you are a fast learner. Keep it up! 🤗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide worker count env variable to processes
2 participants