cypress icon indicating copy to clipboard operation
cypress copied to clipboard

Long running tests get stuck unless we split up the test in multiple 'it' blocks

Open marco-globality opened this issue 1 year ago • 4 comments

Current behavior

Hello all,

We have some tests that take 5+ minutes to run. These tests are intermittently getting stuck at a very high rate.

By stuck, I mean that the CI shows this test running until CI kills the node (at the 1hr mark)

We have found a workaround:

To avoid the issue we split up these tests into multiple 'it' blocks: Basically we have the exact same test running but instead of the test being entirely contained within a single 'it' block we have split up the test so that it is spread out within three 'it' blocks.

Splitting up the test allowed the test to completely stop getting stuck.

Desired behavior

We expect that Cypress should be able to execute long duration tests without them needing to be split up.

Test code to reproduce

Code that causes test to get stuck:

import { aBunchOfStuff } from '../../../stuff/aBunch'

before(function () {
 // do a lil bit of setup...
})

context('This is just some sample code',
    {
        tags: ['@myTest']
    },
    function () {
        it('Complete the first part of the test', function () {
             // Execute the entire test - this test uses a long running recursive function to process a lot of UI actions
        })
    }
)

Working code:

import { aBunchOfStuff } from '../../../stuff/aBunch'

before(function () {
 // do a lil bit of setup...
})

context('This is just some sample code',
    {
        tags: ['@myTest']
    },
    function () {
        it('Complete the first part of the test', function () {
             // Execute the first part of the test - this test uses a long running recursive function to process a lot of UI actions
        })

        it('Complete the second part of the test', function () {
             // Execute the middle part of the test - this test uses a long running recursive function to process a lot of UI actions
        })

        it('Complete the last part of the test', function () {
             // Execute the last part of the test - this test uses a long running recursive function to process a lot of UI actions
        })
        afterEach(function onAfterEach() {
            if (this.currentTest.state === 'failed') {
                cy.log('Fail in test, skipping rest of the tests')
                Cypress.runner.stop()
                //this will skip tests only for current spec
            }
        })
    }
)

Cypress Version

10.10.0

Node version

v16.16.0

Operating System

Debian 11

Debug Logs

No response

Other

  • We feel as though the problem is related to excessive memory consumption by Cypress causing the test crash. We've noticed that the test can reach up to 3000mb (the machine has 8GB available) then this memory consumptions drops dramatically upon the test getting stuck.
  • We also are using a heavy recursive method that we suspect could be contributing to memory usage, however, Cypress recommends using recursion to accomplish loops. It seems alternative methods are not easily accomplished or simply cannot be.

marco-globality avatar Nov 04 '22 18:11 marco-globality

Hi @marco-globality 👋, sorry to hear that Cypress is hanging in your CI pipeline but I'm glad you have a workaround (though definitely not ideal).

Unfortunately, it's going to be very hard for us to investigate this issue without some kind of reproduction. Are you able to share a link to your code or could you try and replicate the issue using the cypress-test-tiny project?

mschile avatar Nov 04 '22 19:11 mschile

Hey @mschile

I understand. Well, I don't think there will be a simple way for us to provide a method of reproducing it. The thing is, our app is internal to my company along with our code.

I was wondering if anyone could speculate as to what may be causing an issue like this.

marco-globality avatar Nov 04 '22 22:11 marco-globality

I wonder if you're running into chrome rendering crashes, in 10.11.0 we are now catching the crashes and continuing the tests where as before it would cause a hang. https://github.com/cypress-io/cypress/issues/6170

Large tests with many snapshots seem to be causing rendering crashes more often since chrome 103 (ish)

Also related #23391

mjhenkes avatar Nov 28 '22 16:11 mjhenkes

You could try chrome 10.11.0 and see if your hangs continue (to be replaced with crashes 😕)

mjhenkes avatar Nov 28 '22 16:11 mjhenkes

Closing as a duplicate of https://github.com/cypress-io/cypress/issues/6170

mjhenkes avatar Dec 06 '22 14:12 mjhenkes