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

Jest failing with "Call retries were exceeded", using --runInBand works-around issue #8769

Open
martijnthe opened this issue Jul 31, 2019 · 89 comments

Comments

@martijnthe
Copy link

🐛 Bug Report

I've got 2 test files. In the test, a WebAssembly object gets instantiated. This instantiation seems to stall for some reason when running the test in CI. Locally running jest passes the tests fine.

In CI they fail with this error:

  ● Test suite failed to run

    Call retries were exceeded

      at ChildProcessWorker.initialize (../node_modules/jest-worker/build/workers/ChildProcessWorker.js:193:21)

When -i is used however, they pass as well in CI.

Jest: 24.8.0
Node: 10.15.0
Local env: macOS, 10.14.6 (18G84))
CI env: CircleCI, Docker Linux 6a7bd3b63625 4.15.0-1035-aws #37-Ubuntu SMP Mon Mar 18 16:15:14 UTC 2019 x86_64 GNU/Linux

To Reproduce

I don't have a concise repro repo at this moment.

Expected behavior

I expect the tests to pass as well when not run in band.

Link to repl or repo (highly encouraged)

Don't have it at this moment.

Run npx envinfo --preset jest

Paste the results here:

CI:

npx: installed 1 in 1.719s

  System:
    OS: Linux 4.15 Debian GNU/Linux 9 (stretch) 9 (stretch)
    CPU: (36) x64 Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz
  Binaries:
    Node: 10.15.0 - ~/.nodenv/versions/10.15.0/bin/node
    Yarn: 1.17.3 - /usr/bin/yarn
    npm: 6.4.1 - ~/.nodenv/versions/10.15.0/bin/npm

Local:

Environment:
  OS:  macOS 10.14.6
  Node:  10.15.0
  Yarn:  1.17.3
  npm:  6.4.1
  Watchman:  Not Found
  Xcode:  Xcode 10.3 Build version 10G8
  Android Studio:  3.1 AI-173.4819257
@lh0x00
Copy link
Contributor

lh0x00 commented Aug 1, 2019

do you use jest-worker? Please provide more information about your use of it if available. or say more about the file that runs your test.

@martijnthe
Copy link
Author

do you use jest-worker?

Not that I’m aware of? I do see it as a dependency in my yarn.lock file.
But I didn’t add any configuration in the jest.config.js for it.

I will try to create a minimal repro example when I find some time.

@lh0x00
Copy link
Contributor

lh0x00 commented Aug 1, 2019

Ok, do you provide a reproduce code?

@martijnthe
Copy link
Author

I will try to create a minimal repro example when I find some time.

@fernandoabolafio
Copy link

Any lucky on this? I am having the same issue after upgrading to node v13.

@creativecomposer
Copy link

I observed that the issue occurs with node v13.2.0, but not with v13.1.0. Looks like the issue with only the latest node version.

@fernandoabolafio
Copy link

@antony2025 same here. After upgrading to node v13.2.0 my test suite which has many async test statements started to fail. Funny thing is that if I delete a few async tests from the test suite it works again.

@degouville
Copy link

Same for me I have the same issue w/ Node 10.17.0

@nelsieborja
Copy link

I just faced the same issue in CI and was able to reproduce it in local by switching to the latest version of node. As suggested, only by downgrading fixes it for me, using -i didn't.

@davidje13
Copy link

davidje13 commented Nov 30, 2019

I have observed the same issue on Node 13.2.0 (where updating node is the only change since it was previously working reliably; package-lock.json has not changed, and I have tried before and after clearing out and rebuilding node_modules).

For me, running with --runInBand results in 8266 Segmentation fault: 11 at the same point where it otherwise fails with Call retries were exceeded at ChildProcessWorker.initialize. I am running on macOS 10.14.6 and installed node via Homebrew. After the crash it notes that it reached 33 passing test suites with 106 total tests. The codebase contains 34 test suites and 122 total tests (I don't know if these numbers are similar for other people hitting the issue?). I have many async tests in the rest of the code but the suite which hits this error contains only synchronous tests.

Since it's segfaulting, I suspect this is a bug in Node itself (seemingly a regression since this was an issue before), but I have no idea where to begin looking!


Is it possible that this could be connected to nodejs/node#26628 ? (seems to be the only entry in the Node 13.2.0 changelog which relates to workers)

@davidje13
Copy link

Appears this issue has been reported upstream: nodejs/node#30730

@rafaelcamargo
Copy link

Hey guys! I was having this issue on CI only (CircleCI). So I changed the following value on CI config file and the issue has gone:

Before

version: 2
jobs:
  build:
    docker:
      - image: circleci/node:latest-browsers

Then

version: 2
jobs:
  build:
    docker:
      - image: circleci/node:12-browsers

@JimiSweden
Copy link

JimiSweden commented Dec 9, 2019

(note: not sure if this is the exact same error reason, but looks like it and I found this link when looking for a solution)

Error:

Test suite failed to run Call retries were exceeded at ChildProcessWorker.initialize (node_modules/jest-worker/build/workers/ChildProcessWorker.js:193:21)

Confirmed fix:

Upgrade from nodejs 13.2.0 to 13.3.0

Environment

I had this error with
Windows 10
nodejs 13.2.0
Yarn 1.19.2

Package.json

"dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-redux": "^7.1.3",
    "react-scripts": "3.3.0",
    "redux": "^4.0.4"
  },
"devDependencies": {
    "@storybook/addon-actions": "^5.3.0-beta.16",
    "@storybook/addon-docs": "^5.3.0-beta.16",
    "@storybook/addon-knobs": "^5.3.0-beta.16",
    "@storybook/addon-links": "^5.3.0-beta.16",
    "@storybook/addon-storyshots": "^5.3.0-beta.16",
    "@storybook/addons": "^5.3.0-beta.16",
    "@storybook/preset-create-react-app": "^1.3.2",
    "@storybook/react": "^5.3.0-beta.16",
    "babel-loader": "^8.0.6",
    "react-test-renderer": "^16.12.0"
  }

Storybook initStoryshots from '@storybook/addon-storyshots'

When following the tutorial in https://www.learnstorybook.com/intro-to-storybook/react/en/simple-component/

The code below is where the error occured.

// src/storybook.test.js
import initStoryshots from '@storybook/addon-storyshots';
initStoryshots();

@asarapas
Copy link

Believe got same issue on Node LTS 12.14.1:

ERROR in main.affbaa778346b006d3f5.js from Terser
Error: Call retries were exceeded
    at ChildProcessWorker.initialize (C:\azagent\A3\_work\1\s\Core\Web\NgApps\node_modules\jest-worker\build\workers\ChildProcessWorker.js:193:21)
    at ChildProcessWorker.onExit (C:\azagent\A3\_work\1\s\Core\Web\NgApps\node_modules\jest-worker\build\workers\ChildProcessWorker.js:263:12)
    at ChildProcess.emit (events.js:223:5)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)

@mvasin
Copy link

mvasin commented May 12, 2020

What helped me was upgrading the runner machine to the one with more memory.

@sibelius
Copy link

sibelius commented Jun 8, 2020

@mvasin how much memory has your machine now?

@gocarlos
Copy link

same with node 10.19.0, ubuntu 20.04

@carbonrobot
Copy link

carbonrobot commented Jun 30, 2020

Working version for our builds: 12.16.3
Broken when upgrading to 12.18.0

Running 16GB memory, 8cpu on circleCI with the following options

yarn --coverage --ci -w 6

@dimagimburg
Copy link

adding --runInBand, worked for me. I don't know why and I don't care as long as i see greens 🟢 🙈

eventualbuddha added a commit to votingworks/module-scan that referenced this issue Aug 19, 2020
This is an attempt to work around jestjs/jest#8769.
@mnmajd
Copy link

mnmajd commented Oct 11, 2021

Guys for me it was just the node version that i use in localhost is not the the same used in the pipeline to run tests !

@azidouk
Copy link

azidouk commented Oct 11, 2021

I am seeing a similar issue with node v16.10.0. In my case, however, I am running locally and --runInBand causes the test to throw:

node:internal/process/promises:246
          triggerUncaughtException(err, true /* fromPromise */);
          ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "Error: For security reasons, `window.crypto` is required to run `auth0-spa-js`.".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

Reverting back to node 12.20.1 resolves the issue but it seems like more than just a node version problem.

@stefdelec
Copy link

stefdelec commented Oct 15, 2021

Similir problem here! Not working on 14 and 16, but works on node 12.

@jamesRaybould
Copy link

jamesRaybould commented Nov 2, 2021

I've run into this issue when updating a codebase from Node12 -> Node16 and in my digging I've found that in the bits that are now failing all seem to have the following in common when I run with a debugger attached.

[DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Which would indicate to me that the behaviour it was relying on, unhandled promise rejections continue, now cause a termination in Node, which Jest is detecting, running the test an additional 3 times before declaring it as dead and marks it as a test suite that has failed to execute.

What is interesting is that in Node12 those tests pass even when unhandled promise rejection is being fired as long as it's not actually impacting any of the bits that are being tested.

Would it be possible to bubble up those Unhandled promise rejection errors so it's easier for people to spot rather than having to spelunk using the debugger to work out what is wrong?

Jest 27.2.3
Node 12.18.2 - All tests work as expected
Node 16.13.0 - Tests that contain an Unhandled promise rejection fail, even if it's not in the tests critical path

@olikari87
Copy link

Having the same problem

jest: 26.6.3
node: 15.5.1

node:internal/process/promises:227
          triggerUncaughtException(err, true /* fromPromise */);

Call retries were exceeded

      at ChildProcessWorker.initialize (node_modules/jest-worker/build/workers/ChildProcessWorker.js:193:21)

@leonheess
Copy link

Same issue here

@yoshicarroll
Copy link

jamesRaybould's description matches the problem I have as well. Worked in node 14.17.16, fails in 16.13.0.

@nvh95
Copy link

nvh95 commented Nov 16, 2021

In my case we're missing an await before wairFor from @testing-library/react

- waitFor(() => {

+ await waitFor(() => {
      expect(screen.getByTestId('my-button')).toBeInTheDocument();

If we run with node 16, it does not complain at all. Node 14 yells Call retries were exceeded without any implicit error message and it's very difficult to spot the bug.

@NeffIsBack
Copy link

Same Problem here:

 FAIL  __tests__/homepage.test.tsx
  ● Test suite failed to run

    Jest worker encountered 4 child process exceptions, exceeding retry limit

      at ChildProcessWorker.initialize (node_modules/jest-worker/build/workers/ChildProcessWorker.js:185:21)

Node version: v16.13.0

Does anyone got a fix?

@jamesRaybould
Copy link

jamesRaybould commented Nov 21, 2021

From my understanding of the problem I think the best fix for this is probably to fix the problem at source, in my case it's a combination of us not mocking out dependencies properly and a couple of places where we don't actually handle the promise rejection (at all). So fixing those will get us to a place where it all works as expected.

I'm not sure that there is a fix that can go in Jest other than to maybe better highlight where the unhandledPromiseRejection is being thrown.

@encreinformatique
Copy link

I had the same problem with a VueJS app, with nodejs v16.13.0 and jest 25.5.4 so a bit older version of Jest.

node:internal/process/promises:246
          triggerUncaughtException(err, true /* fromPromise */);
          ^

and Call retries were exceeded

"Fixed" it with the following changed. I prefer the former syntax than the latter.

    components: {
      VueApexCharts: () => import('vue-apexcharts')
    }

to

    import VueApexCharts from 'vue-apexcharts'
...
    components: {
      VueApexCharts
    }

@mauryakrishna
Copy link

In my case we're missing an await before wairFor from @testing-library/react

- waitFor(() => {

+ await waitFor(() => {
      expect(screen.getByTestId('my-button')).toBeInTheDocument();

If we run with node 16, it does not complain at all. Node 14 yells Call retries were exceeded without any implicit error message and it's very difficult to spot the bug.

Do not know why but this worked like charm.

@regischow
Copy link

For those having issues running on node 16, I found this link helpful,
https://stackoverflow.com/questions/68368577/react-tests-unhandledpromiserejection

Essentially you need to ensure that any custom async functions being called from your tests need to implement a try/catch.

@steevsachs
Copy link

We ran into this issue when upgrading from Node 14 to Node 16. It appears that Node 15 introduced a breaking change to promise rejection handling, as @jamesRaybould indicated earlier. I found https://developer.ibm.com/blogs/nodejs-15-release-blog/ to be a helpful writeup of the change.

We saw the errors disappear after passing the --unhandled-rejections=warn flag to node when running tests, which likely confirms this diagnosis.

Passing that flag may work as a short term workaround.

@arivestNexapp
Copy link

My problem was that a testing-library test was longer than the 5 seconds timeout of a test. There are multiples waitFor in it as it represent an E2E test.

In order to fix it, I simply needed to up the timeout of the test to an higher value:

it('should do a mega long process`, () => {
  renderComponent();
  
  // all the process
  
  expect(true).toBeTruthy()
}, 60 * 1000) // one minute to be sure it does not timeout again

Hope it helps some of you!

@nvh95
Copy link

nvh95 commented Apr 8, 2022

My problem was that a testing-library test was longer than the 5 seconds timeout of a test. There are multiples waitFor in it as it represent an E2E test.

@arivestNexapp Another option is you can configure it globally, so you don't have to manually increase timeout for each test.

import { configure } from '@testing-library/dom';

configure({
  asyncUtilTimeout: 2500,
});

Reference: https://testing-library.com/docs/dom-testing-library/api-configuration#asyncutiltimeout

@dicutaia
Copy link

In my case we're missing an await before wairFor from @testing-library/react

- waitFor(() => {

+ await waitFor(() => {
      expect(screen.getByTestId('my-button')).toBeInTheDocument();

If we run with node 16, it does not complain at all. Node 14 yells Call retries were exceeded without any implicit error message and it's very difficult to spot the bug.

Do not know why but this worked like charm.

In my case, I was not awaiting a findByText. Switching to getByText fixed the issue for me.

@nlasso-longevo
Copy link

Hi, for me this error was related to M1 processor. Run tests on a terminal with rosetta enabled and got it working.

@mohammedabdulai
Copy link

For those having issues running on node 16, I found this link helpful, https://stackoverflow.com/questions/68368577/react-tests-unhandledpromiserejection

Essentially you need to ensure that any custom async functions being called from your tests need to implement a try/catch.

It makes sense that a try/catch block solves the issue because it's a way of catching rejections. Essentially all Promises in tests should catch or handle reject.

@Temirtator
Copy link

mostly, If you met such type of problem you need to take an attention to asynchrous test, perhaps problem related with this

@johnmutuma5
Copy link

johnmutuma5 commented Mar 10, 2023

For me, my problem was with not mocking a dependency exhaustively when some components in the dependency were being used in the component I was testing. For instance

import { A, B } from "dependency";

MyComponent => ({condition}) => {
  if (condition) 
    return <A /> 
  else
    return <B />
}

in my test

// note B is not mocked, it will be undefined
jest.mock("dependency", () => ({
   A: (props) => Something
}))

// condition as false will require B to be defined
it("shows something", () => {
   <MyComponent condition={false} />
})

This would throw this error until I fully mocked the dependency like this (to ensure B is not undefined in the mock):

// note B will now be defined as the unmocked version
jest.mock("dependency", () => ({
   ...jest.requireActual("dependency"),
   A: (props) => Something
}))

While my component also had some async work, that was never the problem.

Try to check if you have some things that are undefined possibly due to mocking.

@lazy-b
Copy link

lazy-b commented Apr 24, 2023

全体起立!
setupTests.js 或者出现问题的单元测试文件添加下面的代码,完美解决!!!

process.on('unhandledRejection', (reason) => {});

参考:https://2ality.com/2016/04/unhandled-rejections.html

@kostyaostapuk
Copy link

kostyaostapuk commented Oct 3, 2023

I was trying to run the craco tests and I got the error:

Test suite failed to run
Call retries were exceeded
at ChildProcessWorker.initialize (node_modules/jest-worker/build/workers/ChildProcessWorker.js:193:21)

I added the option for Node.js for craco test command:

NODE_OPTIONS=--unhandled-rejections=warn craco test

My package.json:

"scripts": {
"test": "NODE_OPTIONS=--unhandled-rejections=warn craco test"
}

@marcostomasello
Copy link

In my case, it was caused by some unit tests where I forgot to return the promise. Once I added the return keyword it showed me the real reason of the failure (which is specific to my code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests