Skip to content

Commit

Permalink
feat(stryker config): rename config setting timeoutMs to timeoutMS (
Browse files Browse the repository at this point in the history
#1099)

Deprecates the `timeoutMs` property. Flat timeout should be set using the `timeoutMS` property.

Fixes #860
  • Loading branch information
Bartosz Leoniak authored and simondel committed Aug 21, 2018
1 parent b2713f6 commit 3ded998
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/stryker-api/src/config/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class Config implements StrykerOptions {

logLevel: LogLevel = LogLevel.Information;
fileLogLevel: LogLevel = LogLevel.Off;
timeoutMs = 5000;
timeoutMS = 5000;
timeoutFactor = 1.5;
plugins: string[] = ['stryker-*'];
port = 9234;
Expand Down
6 changes: 5 additions & 1 deletion packages/stryker-api/src/core/StrykerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,13 @@ interface StrykerOptions {
symlinkNodeModules?: boolean;

/**
* Amount of additional time, in milliseconds, the mutation test is allowed to run
* DEPRECATED PROPERTY. Please use the `timeoutMS` property
*/
timeoutMs?: number;
/**
* Amount of additional time, in milliseconds, the mutation test is allowed to run
*/
timeoutMS?: number;

/**
* The factor is applied on top of the other timeouts when during mutation testing
Expand Down
4 changes: 2 additions & 2 deletions packages/stryker-api/testResources/module/useCore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StrykerOptions, Factory, File, Position, Location, Range, LogLevel } from 'stryker-api/core';
import { StrykerOptions, File, Position, Location, Range, LogLevel } from 'stryker-api/core';

const options: StrykerOptions = {};
const optionsAllArgs: StrykerOptions = {
Expand All @@ -10,7 +10,7 @@ const optionsAllArgs: StrykerOptions = {
reporter: 'string',
repoters: ['reporter'],
logLevel: LogLevel.Fatal,
timeoutMs: 1,
timeoutMS: 1,
timeoutFactor: 2,
plugins: ['string'],
thresholds: {
Expand Down
10 changes: 5 additions & 5 deletions packages/stryker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,23 +259,23 @@ For example, when you set to use port 9234 and Stryker decides to start four tes
If the test runner decides to use the port it should be available for use.

#### Global timeout in milliseconds
**Command line:** `--timeoutMs 5000`
**Config file:** `timeoutMs: 5000`
**Command line:** `--timeoutMS 5000`
**Config file:** `timeoutMS: 5000`
**Default value:** `5000`
**Mandatory**: no
**Description:**
When Stryker is mutating code, it cannot determine indefinitely whether or not a code mutation results in an infinite loop (see [Halting problem](https://en.wikipedia.org/wiki/Halting_problem)).
In order to battle infinite loops, a test run gets killed after a certain period of time. This period is configurable with two settings: `timeoutMs` and `timeoutFactor`.
In order to battle infinite loops, a test run gets killed after a certain period of time. This period is configurable with two settings: `timeoutMS` and `timeoutFactor`.
To calculate the actual timeout in milliseconds the, following formula is used:

```
timeoutForTestRunMs = netTimeMs * timeoutFactor + timeoutMs + overheadMs
timeoutForTestRunMs = netTimeMs * timeoutFactor + timeoutMS + overheadMs
```

Both `netTimeMs` and `overheadMs` are calculated during the initial test run. They are logged on `info` level. For example when `overheadMs` is 92 and `netTimeMs` is 5: `Initial test run succeeded. Ran 6 tests in 4 seconds (net 5 ms, overhead 92 ms).`

With `timeoutFactor` you can configure the allowed deviation relative to the time of a normal test run. Tweak this if you notice that mutants are prone to creating slower code, but not infinite loops.
`timeoutMs` lets you configure an absolute deviation. Use it, if you run Stryker on a busy machine and you need to wait longer to make sure that the code indeed entered an infinite loop.
`timeoutMS` lets you configure an absolute deviation. Use it, if you run Stryker on a busy machine and you need to wait longer to make sure that the code indeed entered an infinite loop.

#### Timeout factor
**Command line:** `--timeoutFactor 1.5`
Expand Down
2 changes: 1 addition & 1 deletion packages/stryker/src/Sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export default class Sandbox {

private calculateTimeout(mutant: TestableMutant) {
const baseTimeout = mutant.timeSpentScopedTests;
return (this.options.timeoutFactor * baseTimeout) + this.options.timeoutMs + this.timeOverheadMS;
return (this.options.timeoutFactor * baseTimeout) + this.options.timeoutMS + this.timeOverheadMS;
}

private getFilterTestsHooks(mutant: TestableMutant): string | undefined {
Expand Down
2 changes: 1 addition & 1 deletion packages/stryker/src/StrykerCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class StrykerCli {
.option('--reporters <name>', 'A comma separated list of the names of the reporter(s) you want to use', this.list)
.option('--plugins <listOfPlugins>', 'A list of plugins you want stryker to load (`require`).', this.list)
.option('--port <n>', 'A free port for the test runner to use (if it needs to). Any additional test runners will be spawned using n+1, n+2, etc', parseInt)
.option('--timeoutMs <number>', 'Tweak the absolute timeout used to wait for a test runner to complete', parseInt)
.option('--timeoutMS <number>', 'Tweak the absolute timeout used to wait for a test runner to complete', parseInt)
.option('--timeoutFactor <number>', 'Tweak the standard deviation relative to the normal test run of a mutated test', parseFloat)
.option('--maxConcurrentTestRunners <n>', 'Set the number of max concurrent test runner to spawn (default: cpuCount)', parseInt)
.option('--logLevel <level>', 'Set the log level for the console. Possible values: fatal, error, warn, info, debug, trace, all and off. Default is "info"')
Expand Down
5 changes: 5 additions & 0 deletions packages/stryker/src/config/ConfigReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export default class ConfigReader {
this.log.warn(`DEPRECATED: please change the config setting 'reporter: ${JSON.stringify(config.reporter)}' into 'reporters: ${JSON.stringify(config.reporters)}'`);
}

if (config.timeoutMs) {
config.timeoutMS = config.timeoutMs;
this.log.warn(`DEPRECATED: please change the config setting 'timeoutMs: ${config.timeoutMs}' into 'timeoutMS: ${config.timeoutMS}'`);
}

return config;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/stryker/src/config/ConfigValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default class ConfigValidator {
}

private validateTimeout() {
this.validateIsNumber('timeoutMs', this.strykerConfig.timeoutMs);
this.validateIsNumber('timeoutMS', this.strykerConfig.timeoutMS);
this.validateIsNumber('timeoutFactor', this.strykerConfig.timeoutFactor);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/stryker/src/process/InitialTestExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default class InitialTestExecutor {
* grossTime = NetTime + overheadTime
*
* The overhead time is used to calculate exact timeout values during mutation testing.
* See timeoutMs setting in README for more information on this calculation
* See timeoutMS setting in README for more information on this calculation
*/
private calculateTiming(grossTimeMS: number, tests: ReadonlyArray<TestResult>): Timing {
const netTimeMS = tests.reduce((total, test) => total + test.timeSpentMs, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ describe('ConfigReader', function () {
expect(result.reporters).to.deep.eq(configuredReporters);
expect(log.warn).calledWithExactly(`DEPRECATED: please change the config setting 'reporter: ${JSON.stringify(configuredReporters)}' into 'reporters: ${JSON.stringify(configuredReporters)}'`);
});

it('should log a warning when timeoutMs is specified', () => {
const timeoutMs = 30000;
sut = new ConfigReader({ timeoutMs: timeoutMs });

const result = sut.readConfig();

expect(result.timeoutMS).to.deep.eq(timeoutMs);
expect(log.warn).calledWithExactly(`DEPRECATED: please change the config setting 'timeoutMs: ${timeoutMs}' into 'timeoutMS: ${timeoutMs}'`);
});
});
});
});
6 changes: 3 additions & 3 deletions packages/stryker/test/unit/SandboxSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('Sandbox', () => {
let log: Mock<Logger>;

beforeEach(() => {
options = { port: 43, timeoutFactor: 23, timeoutMs: 1000, testRunner: 'sandboxUnitTestRunner', symlinkNodeModules: true } as any;
options = { port: 43, timeoutFactor: 23, timeoutMS: 1000, testRunner: 'sandboxUnitTestRunner', symlinkNodeModules: true } as any;
testRunner = { init: sandbox.stub(), run: sandbox.stub().resolves(), dispose: sandbox.stub() };
testFrameworkStub = {
filter: sandbox.stub()
Expand Down Expand Up @@ -198,12 +198,12 @@ describe('Sandbox', () => {
});

it('should provide the filter code as testHooks and correct timeout', async () => {
options.timeoutMs = 1000;
options.timeoutMS = 1000;
const overheadTimeMS = 42;
const totalTimeSpend = 12;
const sut = await Sandbox.create(options, SANDBOX_INDEX, files, testFrameworkStub, overheadTimeMS, LOGGING_CONTEXT);
await sut.runMutant(transpiledMutant);
const expectedRunOptions = { testHooks: wrapInClosure(testFilterCodeFragment), timeout: totalTimeSpend * options.timeoutFactor + options.timeoutMs + overheadTimeMS };
const expectedRunOptions = { testHooks: wrapInClosure(testFilterCodeFragment), timeout: totalTimeSpend * options.timeoutFactor + options.timeoutMS + overheadTimeMS };
expect(testRunner.run).calledWith(expectedRunOptions);
});

Expand Down
6 changes: 3 additions & 3 deletions packages/stryker/test/unit/config/ConfigValidatorSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ describe('ConfigValidator', () => {
expect(log.fatal).calledWith('Value "thisTestPasses" is invalid for `logLevel`. Expected one of the following: "fatal", "error", "warn", "info", "debug", "trace", "off"');
});

it('should be invalid with nonnumeric timeoutMs', () => {
let brokenConfig = breakConfig(config, 'timeoutMs', 'break');
it('should be invalid with nonnumeric timeoutMS', () => {
let brokenConfig = breakConfig(config, 'timeoutMS', 'break');
sut = new ConfigValidator(brokenConfig, testFramework());
actValidationError();
expect(log.fatal).calledWith('Value "break" is invalid for `timeoutMs`. Expected a number');
expect(log.fatal).calledWith('Value "break" is invalid for `timeoutMS`. Expected a number');
});

it('should be invalid with nonnumeric timeoutFactor', () => {
Expand Down

0 comments on commit 3ded998

Please sign in to comment.