-
Notifications
You must be signed in to change notification settings - Fork 250
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
Conversation
There was a problem hiding this 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.
private childId: number; | ||
constructor() { | ||
this.childId = 0; | ||
} | ||
public next(): number { | ||
return this.childId++; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is good 👌
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 | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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? :/ |
@@ -20,15 +22,17 @@ createTestRunnerFactory.inject = tokens( | |||
coreTokens.sandbox, | |||
coreTokens.loggingContext, | |||
commonTokens.getLogger, | |||
coreTokens.pluginModulePaths | |||
coreTokens.pluginModulePaths, | |||
'worker-id-generator' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'worker-id-generator' | |
coreTokens.workerIdGenerator |
beforeEach(() => { | ||
idGenerator = new IdGenerator(); | ||
}); | ||
it('should increment workerId on calling `next`', async () => { |
There was a problem hiding this comment.
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
.
There was a problem hiding this 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 👍.
Made the changes, @nicojs. Thanks for the review and helping me through my first open source contribution 😄 |
There was a problem hiding this 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!
I've released this feature in 6.3 🎉 This feature still needs documentation. I've opened #3828 for it. Feel free to pick it up if you want 😉 |
The first of many, I hope 🤝. My pleasure; you are a fast learner. Keep it up! 🤗 |
Fixes #3231