https://cypress.io logo
Cypress run test randomly failing because of 100% ...
# i-need-help
b
Hello, I have a react project where I have 38 e2e cypress test files. I run these test cases on Circle CI in headless mode (cypress run) It's been a long time any random test file is started failing with element not found or API intercept didn't worked. By when I run the same failed test in cypress open mode it works fine. This has become a blocker for me to promote new changes to production because cypress does not get pass. I am using cypress 9 I run my cypress in Large Docker container (i.e 4 CPU, 8 GB RAM) on Circle CI. Please help to resolve this issue. Thanks
a
These are typical signs of a machine resource issue. That being said, Cypress 12.4 (https://docs.cypress.io/guides/references/changelog#12-4-0) allows you to set
experimentalMemoryManagement=true
if you have experienced "Out of Memory" issues. That would be the first recommendation. You mention the machine resources are exhausted so the second recommendation would be to increase those resources because the amount of resources Cypress uses is heavily dependent on the underlying application. You may need a larger Docker image or increase the number of machines. You may also need to split your longer running tests into shorter tests (https://www.cypress.io/blog/2019/10/29/split-a-very-long-cypress-test-into-shorter-ones-using-app-actions/). A longer running test is considered any test that runs longer than 1 minute. Another option would be to update video options by setting
video-false
or
videoUploadOnPasses=true
in your cypress.config. The exact cause isn't always clear as this can be a combination of any number of things, but you can check to see how much resources are being used with CPU and memory usage logs enabled (https://docs.cypress.io/guides/references/troubleshooting.html#Log-memory-and-CPU-usage)
b
@adventurous-dream-20049 Thanks for the suggestion, I'll try these and will get back to you
e
You could possibly add this in your config file to see if that solves the issue
numTestsKeptInMemory: 0
That 8GB RAM seems pretty small though to be honest.
l
@echoing-tent-95037
Copy code
numTestsKeptInMemory: 0
is a good way to save memory but I think that affects the screenshots & videos even on failure. I do keep a small number when running locally but in ci env, I think that might be needed if you need something to analyze your runs and results.
e
I thought that was more for the local runner, won't the cypress dashboard still record tests with that set to 0?
l
That's actually a great question. I guess will have to try it. My initial instinct says no but I have been wrong way too many times in the past as well 😛
e
haha same.
b
@late-greece-72449 / @echoing-tent-95037 - Thank you for your valuable suggestion. Should I keep it?
Copy code
numTestsKeptInMemory: 0
l
I think it would be worth the try.
b
numTestsKeptInMemory: 0 only affect local
cypress open
runs and not headless
cypress run
so take that under consideration
f
isn't working for me, i set the numTestsKeptInMemory: 0 and still consuming all my cpu after one or two runs of all the tests even if these are very simple, like the demo spec of cypress.
2 Views