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

fix(testing): fix race condition in tests for parallel commands runner #2358

Merged
merged 3 commits into from
Jan 24, 2020

Conversation

rarmatei
Copy link
Collaborator

@rarmatei rarmatei commented Jan 21, 2020

Current Behavior (This is the behavior we have today, before the PR is merged)

Test would occasionally fail.

Expected Behavior (This is the new behavior we can expect after the PR is merged)

Test should consistently pass now.

Issue

The previous setup was as follows:

  • command_1 was sleeping for 0.2 seconds before running
  • command_2 was sleeping for 0.1 seconds before running
    The idea was that, if truly running in parallel, the second commands would finish before the first, because it was sleeping for less.

But as @jaysoo pointed out, if they're running in parallel we can't guarantee order, even with sleep.

Fix (checked-in / part of this PR)

Instead of checking the order in which the commands were executed we now:

  • invoke the commands runner synchronously
  • immediately checked if there were 2 calls to spawn the processes
  • wait for the promise/tasks to finish and check whether they both appended to the file (we do not check for order, just presence)

To prove above strategy works, it's also been added to the serial runner tests, and it indeed just prints 0 (as the initial promise it creates is a null one, only once that resolves it schedules the first task in the queue)

We are now checking for the presence of both command outputs regardless of the order they were
written in to the file
@rarmatei rarmatei requested a review from FrozenPandaz January 21, 2020 15:29
… parallel

In addition to checking whether the tasks complete and they write to the file, we are now also
checking if the runner creates all the tasks synchronously when invoked with parallel: true, vs.
zero or at most 1 when ran in serial mode.
@rarmatei rarmatei marked this pull request as ready for review January 24, 2020 12:51
}
],
parallel: true
}
);
const processesCreated = exec.calls.count();

This comment was marked as resolved.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment in the right place? :)

Copy link
Collaborator Author

@rarmatei rarmatei Jan 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added your suggestion to the serial runner tests 👍 please let me know if that's not what you meant

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah

Due to differences in implementation between serial and parallel runner, we need to wait for a
micro-tick in the serial test runner tests before checking for calls to spawn-process, otherwise it
would be zero.
@FrozenPandaz FrozenPandaz merged commit 616fbd6 into nrwl:master Jan 24, 2020
@github-actions
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants