-
Notifications
You must be signed in to change notification settings - Fork 251
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(hit limit): infinite loop prevention in karma-runner #3031
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nicojs
changed the title
Feat/hit counter
feat(hit limit): implement infinite loop prevention in karma-runner
Aug 2, 2021
nicojs
changed the title
feat(hit limit): implement infinite loop prevention in karma-runner
feat(hit limit): infinite loop prevention in karma-runner
Aug 2, 2021
@hcoles I've decided to go with your approach of using the dry-run result to determine the 'normal' hit count as you can see in the description. Thanks again for that great insight. |
@nicojs Glad someone is going to implement it. |
simondel
approved these changes
Aug 6, 2021
packages/core/test/unit/process/4-mutation-test-executor.spec.ts
Outdated
Show resolved
Hide resolved
packages/karma-runner/src/karma-plugins/stryker-mutant-coverage-adapter.ts
Outdated
Show resolved
Hide resolved
packages/karma-runner/src/karma-plugins/stryker-mutant-coverage-adapter.ts
Outdated
Show resolved
Hide resolved
Looks good! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add infinite loop prevention using a hit counter in the core and the karma runner.
I want to add this functionality to the other test runners as well, but first want to see how it behaves in the wild. The karma runner is also the most expensive one to restart, so it has the most to gain with this functionality.
During mutation testing, Stryker might create an infinite loop. For example:
In the past, Stryker would eventually report a timeout. This is expensive because Stryker has to kill the test runner process and start a new one. This can take anywhere from less than a second to multiple minutes, depending on the test runner.
With this PR, infinite-loop-prevention code is generated during code instrumentation:
As you can see, an error is thrown when a limit is reached. This hopefully breaks the infinite loop but it might not, since the error can be caught and handled by user-code inside the loop, making it infinite once again. I don't see a way around this, since js has no
goto
statement and I don't know of another way to "break out of infinity". In such cases, the timeout will still occur and the test runner process will be killed.The job of preventing infinite loops is a shared responsibility between Stryker and the test runner plugin.
hitLimit
and reset thehitCount
on the__stryker__
variable and determining whether or not the hit limit was reached.Important to note is that this functionality is optional. If the test runner doesn't set the
__stryker__.hitCount
and__stryker.hitLimit
variables, the functionality will simply be ignored.The hit limit is provided to the test runner in the
MutantRunOptions
. Stryker calculates it using thehitCount
from the dry run:Choosing a good
hitLimitFactor
here is crucial. If the value is too low, it might increase false positives. If the value is too high, it might take longer to complete. However, I've chosen to start with a factor of100
, to lean to the save side. We might want to make this factor configurable in the future.Note that there are theoretical cases where this functionality results in false positives, no matter how high we make the
hitLimitFactor
. For example:There is one case I can think of that isn't theoretical. Namely when someone is using a property testing library, like jsverify. During property testing, a failing scenario might be executed a lot of times to determine the smallest possible counterexample. I haven't tested this yet, but I am planning to do that.
List of changes:
hitLimit
to theMutantRunOptions
hitCount
andhitLimit
toInstrumenterContext
hitCount
toMutantTestCoverage
result.reason
field toTimeout
test runner results.determineHitLimitReached
helper function to determine wether or not a hit limit is reachedhitCount
based on the mutant coverage.hitLimit
based on thehitCount
and provide it inMutantRunOptions
hitLimit
and configure it using the test hooks middleware.determineHitLimitReached
helper.hit-limit
e2e test.Closes #3023