Yarn test hangs when one more tests file is added

Hi All,

I’m running a project that has several test suites (Jest), all passing locally.
I have a step in my CircleCI job that simply runs yarn test.

The problem is that the entire build hangs during the yarn test step. The tests all pass, but the step just hangs, and times out after 10 min.

CircleCI

To make thing more interesting, if I remove one test suite file from my tests folder, the step will pass. I can remove any tests file, it will still pass. That means there is nothing wrong with my tests. Also, if I remove one file, and add a new file with just one dummy test, the step will hang again.

What am I overlooking? (NOTE: using a free account)

Thanks!

That is strange. Are you running any browser tests? Those tend to hang in strange ways and can cause timeouts.

No, server side only.

But it will also consistently succeed until I add one more test file. And then consistently hang.

And it doesn’t matter what the test is? It can be any test?

What about if you add a test and roll your cache keys? Any change?

I am not caching anything during this job.

And yes, it doesn’t matter what the test is. I tried right now adding a file named dummy.test.ts with this content:

test('dummy', (done) => { done(); })

and the build got stuck again. the build before passed.

What happens if you try SSH’ing in, does it still hang? Does it give more details, or can you add more verbosity?

I had much more verbosity, which I suppressed.
Tried running Jest with --detectOpenHandles. It just hangs, nothing happens.

I’d love some help trying to figure out how to troubleshoot via SSH.

Sure, these steps https://circleci.com/docs/2.0/ssh-access-jobs/ will walk you though how to SSH into the box. I would then suggest running the tests again to see where and how they hang.

Via SSH the tests pass :confused:
(I ran them 3 times, just to make sure).

When I ran ‘Rebuild with SSH’ I got this message during the tests (it wasn’t there before):
ENOMEM: not enough memory, read

Hrm. Can you open a ticket with the build URL? I’d like to take a look and see if I can spot anything strange. Please ping me the ticket number.

Ticket #47071

I’m seeing the same thing with yarn test and jest v24… It’s really intermittent and sometimes just restarting the build a few times will make it work… Not sure what’s going on either…

Actually I think it’s related to the issue listed here https://github.com/facebook/jest/issues/5239#issuecomment-355867359

adding --runInBand to your jest command will fix it and dramatically speed up your tests.

1 Like

For me the problem is very consistent. But I peeked at the github thread you linked, @besquared, and setting -w=2 worked!

Edit for future readers: setting -w=2 limits the number or worker Jest uses to 2. I assume this can be raised to more workers in paid account with stronger machines, but 2 works great for free accounts, which run machines with 2 cores.

1 Like

For the record I found this solution in the CircleCI docs but just no in the place you’d expect… It was linked at the bottom of this article:

https://circleci.com/docs/2.0/collect-test-data/#jest

1 Like

@besquared That’s good feedback. Our docs are open-source so PRs welcome, but where would be a better place to surface this information?

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.