-
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
Changes from 4 commits
e56b6aa
b5baf75
a30b41f
d0901c4
056fec8
e32aec5
d85804a
47525b9
9d90ae0
7f55a39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,9 @@ | ||||||||||||||||||||||||
export class IdGenerator { | ||||||||||||||||||||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ import { TemporaryDirectory } from '../utils/temporary-directory.js'; | |
import { UnexpectedExitHandler } from '../unexpected-exit-handler.js'; | ||
import { FileSystem, Project } from '../fs/index.js'; | ||
|
||
import { IdGenerator } from '../child-proxy/id-generator.js'; | ||
|
||
import { DryRunContext } from './3-dry-run-executor.js'; | ||
|
||
export interface MutantInstrumenterContext extends PluginContext { | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. We should add the |
||
.provideFactory(coreTokens.checkerFactory, createCheckerFactory) | ||
.provideFactory(coreTokens.checkerPool, createCheckerPool); | ||
const checkerPool = checkerPoolProvider.resolve(coreTokens.checkerPool); | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,6 +7,8 @@ import { LoggingClientContext } from '../logging/index.js'; | |||||
import { coreTokens } from '../di/index.js'; | ||||||
import { Sandbox } from '../sandbox/sandbox.js'; | ||||||
|
||||||
import { IdGenerator } from '../child-proxy/id-generator.js'; | ||||||
|
||||||
import { RetryRejectedDecorator } from './retry-rejected-decorator.js'; | ||||||
import { TimeoutDecorator } from './timeout-decorator.js'; | ||||||
import { ChildProcessTestRunnerProxy } from './child-process-test-runner-proxy.js'; | ||||||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
); | ||||||
export function createTestRunnerFactory( | ||||||
options: StrykerOptions, | ||||||
fileDescriptions: FileDescriptions, | ||||||
sandbox: Pick<Sandbox, 'workingDirectory'>, | ||||||
loggingContext: LoggingClientContext, | ||||||
getLogger: LoggerFactoryMethod, | ||||||
pluginModulePaths: readonly string[] | ||||||
pluginModulePaths: readonly string[], | ||||||
idGenerator: IdGenerator | ||||||
): () => TestRunner { | ||||||
if (CommandTestRunner.is(options.testRunner)) { | ||||||
return () => new RetryRejectedDecorator(() => new TimeoutDecorator(() => new CommandTestRunner(sandbox.workingDirectory, options))); | ||||||
|
@@ -48,7 +52,8 @@ export function createTestRunnerFactory( | |||||
sandbox.workingDirectory, | ||||||
loggingContext, | ||||||
pluginModulePaths, | ||||||
getLogger(ChildProcessTestRunnerProxy.name) | ||||||
getLogger(ChildProcessTestRunnerProxy.name), | ||||||
idGenerator | ||||||
) | ||||||
), | ||||||
options | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,20 +8,23 @@ import { CheckerChildProcessProxy } from '../../../src/checker/checker-child-pro | |
import { CheckerWorker } from '../../../src/checker/checker-worker.js'; | ||
import { ChildProcessProxy } from '../../../src/child-proxy/child-process-proxy.js'; | ||
import { LoggingClientContext } from '../../../src/logging/index.js'; | ||
import { IdGenerator } from '../../../src/child-proxy/id-generator.js'; | ||
|
||
describe(CheckerChildProcessProxy.name, () => { | ||
let childProcessProxyCreateStub: sinon.SinonStubbedMember<typeof ChildProcessProxy.create>; | ||
let loggingContext: LoggingClientContext; | ||
let fileDescriptions: FileDescriptions; | ||
let idGenerator: IdGenerator; | ||
|
||
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 commentThe 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 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 commentThe reason will be displayed to describe this comment to others. Learn more. I've made similar changes in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that is good 👌 |
||
}); | ||
|
||
function createSut(): CheckerChildProcessProxy { | ||
return new CheckerChildProcessProxy(testInjector.options, fileDescriptions, ['plugin', 'paths'], loggingContext); | ||
return new CheckerChildProcessProxy(testInjector.options, fileDescriptions, ['plugin', 'paths'], loggingContext, idGenerator); | ||
} | ||
|
||
describe('constructor', () => { | ||
|
@@ -36,7 +39,8 @@ describe(CheckerChildProcessProxy.name, () => { | |
['plugin', 'paths'], | ||
process.cwd(), | ||
CheckerWorker, | ||
[] | ||
[], | ||
idGenerator | ||
); | ||
}); | ||
it('should provide arguments', () => { | ||
|
@@ -51,7 +55,8 @@ describe(CheckerChildProcessProxy.name, () => { | |
sinon.match.any, | ||
sinon.match.any, | ||
sinon.match.any, | ||
['foo', 'bar'] | ||
['foo', 'bar'], | ||
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 shouldn't forget to also pass along the
process.env
of the parent process.