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

Race condition in the MutationTestExecutor #3473

Closed
nicojs opened this issue Mar 29, 2022 · 2 comments · Fixed by #3485
Closed

Race condition in the MutationTestExecutor #3473

nicojs opened this issue Mar 29, 2022 · 2 comments · Fixed by #3485
Labels
🐛 Bug Something isn't working
Milestone

Comments

@nicojs
Copy link
Member

nicojs commented Mar 29, 2022

The MutationTestExecutor has a race condition here:

const group$ = this.checkerPool
.schedule(input$.pipe(bufferTime(CHECK_BUFFER_MS)), (checker, mutants) => checker.group(checkerName, mutants))
.pipe(mergeMap((mutantGroups) => mutantGroups));
const checkTask$ = this.checkerPool
.schedule(group$, (checker, group) => checker.check(checkerName, group))
.pipe(
mergeMap((mutantGroupResults) => mutantGroupResults),
shareReplay(),
map(([mutantRunPlan, checkResult]) =>
checkResult.status === CheckStatus.Passed
? mutantRunPlan
: {
plan: PlanKind.EarlyResult as const,
mutant: this.mutationTestReportHelper.reportCheckFailed(mutantRunPlan.mutant, checkResult),
}
)
);
return checkTask$;

As you can see, .schedule() is called twice in quick succession. This isn't supported by the Pool class. Only one schedule() can be called at the same time. A call to schedule() creates some internal bookkeeping variables that are local to the function itself, any subsequent calls don't share that state and instead cause new bookkeeping variables to be created. This results in parallel calls to the checker (calls to check while a call to group is active).

@nicojs nicojs added the 🐛 Bug Something isn't working label Mar 29, 2022
@nicojs nicojs added this to the 6.0 milestone Mar 29, 2022
@nicojs
Copy link
Member Author

nicojs commented Mar 31, 2022

I've created the branch feat/pool-schedule which contains a unit test that forces the bug.

I have no clear solution for this. I'm thinking that what we want to achieve (a pool of resources shared by consumers) is not possible with standard RXJS operators. Maybe we should simply program it ourselves using plain old arrays or something 😢

@nicojs
Copy link
Member Author

nicojs commented Mar 31, 2022

I've also opened a stackoverflow question about it. You never know 🤞
https://stackoverflow.com/questions/71689376/how-to-use-rxjs-to-share-a-pool-of-resources-between-multiple-consumers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant