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

Tests hang when afterEach promise does not resolve with Retires enabled #21619

Closed
taylorjellsworth opened this issue May 24, 2022 · 19 comments
Closed
Labels
E2E Issue related to end-to-end testing pkg/driver This is due to an issue in the packages/driver directory stale no activity on this issue for a long period type: bug

Comments

@taylorjellsworth
Copy link

taylorjellsworth commented May 24, 2022

Current behavior

I recently noticed that our e2e tests periodically fail the first run and then randomly hang on the retry run. After outputting cypress logs via DEBUG='cypress:*' I found the following:

  • The test:after:run event never gets fired when the test hang on the retry run, The test:after:run event is supposed to happen after the afterEach and after Mocha hooks run
  • We get an onMocha hook output, which means that the afterEach hook has started
  • We never receive an onMocha hook end output. This signifies the afterEach hook has never finished. So the afterEach hook is hanging for some reason
    Screen Shot 2022-05-10 at 10 14 06 AM

It appears to me that the tests are hanging when retries are enabled and the afterEach promise does not resolve

Desired behavior

During the first retry, Cypress should reach timeout and fail. The test should not hang.

Test code to reproduce

I am unable to share test code/logs due to proprietary rights. However, I was able to reproduce a similar error where the test hangs on first retry when the done() callback is never invoked.

In cypress.json

"retries": {
    "runMode": 1,
    "openMode": 1
 }

Test Case

describe('Cypress Tests Hang', () => {
  it('Cypress Tests Hang', () => {
    cy.visit('https://www.google.com');
  });

  afterEach(run => {
    cy.log('In afterEach');
  });
});

You'll see that the first run fails, and the retry run will end up hanging

Screen Shot 2022-05-24 at 2 51 46 PM

Cypress Version

9.7.0

Other

No response

@cypress-bot cypress-bot bot added the stage: investigating Someone from Cypress is looking into this label May 25, 2022
@ZachJW34
Copy link
Contributor

I was able to reproduce this with latest Cypress (9.7.0). Like you are suggesting @taylorjellsworth, there seems to be something going wrong with how we are processing the fail event for hooks that timeout. I think a timeout of the hook should act the same as an error occurring within the hook.

Here is a snapshot of the fail function executing when throwing an error in an afterEach
Screen Shot 2022-05-25 at 5 41 30 PM

With the timeout, the breakpoint is never reached
Screen Shot 2022-05-25 at 5 42 20 PM

Thanks for posting the issue, we'll add this bug to our backlog.

@ZachJW34 ZachJW34 added pkg/driver This is due to an issue in the packages/driver directory type: bug labels May 25, 2022
@taylorjellsworth
Copy link
Author

@ZachJW34 Thanks for investigating! I agree, I think a timeout of the hook should act the same as an error occurring within the hook.

If it's possible, can this bug be prioritized? This is currently impacting our test suites, and if it gets stuck in the backlog we'd be forced to move off of Cypress (even though we really don't want to!)

@cypress-bot cypress-bot bot added stage: routed to e2e-core and removed stage: investigating Someone from Cypress is looking into this labels May 26, 2022
@jennifer-shehane
Copy link
Member

Maybe related to code-coverage plugin? Maybe there's an afterEach promise in there that doesn't resolve sometimes.

@taylorjellsworth
Copy link
Author

I was wondering if there are any updates on this?

@taylorjellsworth
Copy link
Author

Hi @jennifer-shehane ! This is still causing us issues, I was wondering if anyone has started looking into it yet?

@mschile mschile added triage and removed triage labels Aug 18, 2022
@ivanspasov99
Copy link

Facing the same issue. When using cy.request().then() on before or when there are more than 2 it cypress stucks.

It strange because if I put the logic inside one it it works if that helps somehow.

@flotwig
Copy link
Contributor

flotwig commented Aug 22, 2022

Similar issue here: #18502

@taylorjellsworth
Copy link
Author

@flotwig I was wondering if there's any estimate on when this will get looked at? We are still running into this issue.

@taylorjellsworth
Copy link
Author

taylorjellsworth commented Nov 3, 2022

@flotwig @mjhenkes @jennifer-shehane @mschile bump. We are close to moving off of Cypress if this is not addressed

@Regaddi
Copy link

Regaddi commented Nov 8, 2022

I'd like to add that not being able to use retries also increases costs.
In our app there is always some network flakiness to expect, so tests can sporadically fail without a corresponding change to the application.
We currently have a test suite of 120 Cypress tests.
Every time a test fails due to some flakiness that could otherwise be covered with the retries option, we'd have to re-run the tests, which typically adds $0,72 to our bill for Cypress plus CI costs. (I know this isn't a super fair comparison, but I'd prefer knowing that a test passed in a second run than not re-running the test at all).
While I understand that fixing this issue is not necessarily in the interest of the Cypress team (because it drives revenue) it's certainly annoying enough to start considering alternatives (echo-ing @taylorjellsworth).

@nagash77 nagash77 added E2E Issue related to end-to-end testing and removed E2E-core labels Nov 8, 2022
@tgdevereux
Copy link

tgdevereux commented Nov 10, 2022

Just to add to this, we appear to be hitting a similar issue, however it appears to happen regardless of retries being set.
And we’re repro-ing it when we hit a separate file download issue, possibly related to #1551

Basically, we have a test that downloads a file, and then hits a pageLoadTimeout, perhaps due to #1551
But if I have an afterEach block after this test (which just clicks a back button on the page), the test doesn’t throw the pageLoadTimeout error, and the test just hangs indefinitely. The tests are written in Typescript, running against a React UI.

Repro’d with:
Cypress version: 10.11.0
OS: macOS Big Sur (v11.7)
Browser version: Chrome 105.0.5195.125

@taylorjellsworth
Copy link
Author

fyi - we have moved off of Cypress completely and onto Playwright due to this issue. We would have loved to continue to use Cypress, but the lack of communication (even after asking for updates many times) on this issue was the driving force. We could not wait around forever. Hopefully this issue gets resolved at some point for those who are still dealing with it.

@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label Aug 15, 2023
@cypress-app-bot
Copy link
Collaborator

This issue has been closed due to inactivity.

@cypress-app-bot cypress-app-bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 30, 2023
@mikhail-g
Copy link

I faced the same issue, it would be really nice having it fixed. Now we cannot use afterEach when having retries, it's very inconvenient

@cypress-app-bot cypress-app-bot removed the stale no activity on this issue for a long period label Apr 12, 2024
@ptrcortes
Copy link

I'm also experiencing this issue with Cypress 12. Would love a fix.

@sbfrancies-onyx
Copy link

I am experiencing this in cypress 13.11.0, my tests can hang indefinitely both locally and in an Azure Devops Pipeline when there are failures with retries enabled (we are using the cypress-cucumber-preprocessor which uses afterEach). The same behaviour does not appear to occur when retries are not enabled.

@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label Dec 4, 2024
@cypress-app-bot
Copy link
Collaborator

This issue has been closed due to inactivity.

@cypress-app-bot cypress-app-bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E2E Issue related to end-to-end testing pkg/driver This is due to an issue in the packages/driver directory stale no activity on this issue for a long period type: bug
Projects
None yet
Development

No branches or pull requests