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

Mocking Math.random Causes Random birpc Timeouts #2230

Closed
6 tasks done
alexlafroscia opened this issue Oct 28, 2022 · 3 comments · Fixed by #2254
Closed
6 tasks done

Mocking Math.random Causes Random birpc Timeouts #2230

alexlafroscia opened this issue Oct 28, 2022 · 3 comments · Fixed by #2254

Comments

@alexlafroscia
Copy link

alexlafroscia commented Oct 28, 2022

Describe the bug

For weeks, my application has been plagued by flakey failures due to different forms of the following error:

Error: [birpc] timeout on calling "onAfterSuiteRun"

Where "onAfterSuiteRun" was sometimes "snapshotSaved" or "onTaskUpdate" instead. When this happened, all of my tests would pass, but after completing the tests there would be a long pause followed by the test suite eventually failing due to the above error from somewhere within Vitest itself.

Sometimes, depending on which task timed out, the reporter UI in the terminal would end up in some kind of odd state (like a test never being marked as having completed and passed, despite having done so).

I found #1154, which is the only issue I could find related at all to birpc, but that didn't lead to any insights on how to resolve my problem.

I eventually thought to look in Discord and found this message from May, which described the same issue that I ran into along with something useful -- the error seems related to stubbing Math.random!

Sure enough, I adjusted my code to avoid the Math.random stub and I haven't seen a single one of these errors since!

Reproduction

I have a StackBlitz here that can sometimes show the issue.

Unfortunately, because it's flakey test behavior, I have been unable to consistently reproduce the error (both locally in my app's test suite, before I replaced the Math.random mock, or in StackBlitz). However, after enough times re-running the tests in StackBlitz, I eventually saw the issue a few times

CleanShot 2022-10-28 at 11 05 35@2x

CleanShot 2022-10-28 at 11 10 58@2x

System Info

N/A -- see reproduction in StackBlitz

Used Package Manager

npm

Validations

@sheremet-va
Copy link
Member

sheremet-va commented Oct 28, 2022

I think we can add original Math.random, when running withSafeTimers, PR welcome

@rasyidf
Copy link

rasyidf commented May 18, 2023

xcuse me, this problem presist again on 0.31.1
image

I've had to revert into 0.30.1 to make it work again.

@sheremet-va
Copy link
Member

xcuse me, this problem presist again on 0.31.1 image

I've had to revert into 0.30.1 to make it work again.

Create a separate issue with reproduction.

@vitest-dev vitest-dev locked as resolved and limited conversation to collaborators May 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants