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

Spec hangs when error thrown in test:after:run listener #8701

Closed
oleksiydubovykTR opened this issue Sep 30, 2020 · 9 comments · Fixed by #8709
Closed

Spec hangs when error thrown in test:after:run listener #8701

oleksiydubovykTR opened this issue Sep 30, 2020 · 9 comments · Fixed by #8709
Assignees
Labels
type: duplicate This issue or pull request already exists

Comments

@oleksiydubovykTR
Copy link

oleksiydubovykTR commented Sep 30, 2020

Related to #8363, basically the same issue.

I've been waiting for the fix for quite a long time, and kind of disappointed to see that it seems that it still hangs for the cy.get().should() assertions, in both cy run and cy open, in both 5.2.0 and 5.3.0.

cy run

image

cy open

image

I obviously just changed the expected Log Out button text to Log OutZZZ, and that's it, the test will hang for 4 hours in your CI, and will never retry, or skip to other tests.

@bahmutov
Copy link
Contributor

Can you provide a reproducible example, we believe we have fixed it in #8363 but seems something else in your particular situation causes a problem

@bahmutov bahmutov added the stage: needs information Not enough info to reproduce the issue label Sep 30, 2020
@NurmemetAbliz
Copy link

I have the same issue . My tests in CI nightly build are normally completed around 2 hours . But it is still running even after 8-9 hours recently for the same number of tests and the same test execution environment , and it looks like never ending . So currently I am having no choice but to cancel the tests .

@oleksiydubovykTR
Copy link
Author

Can you provide a reproducible example, we believe we have fixed it in #8363 but seems something else in your particular situation causes a problem

@bahmutov
Hi Gleb, yep, you're right. I managed to create a repro:

https://github.com/dubbha/cypress-test-tiny/tree/issue8701%405.3.0
https://github.com/cypress-io/cypress-test-tiny/compare/master...dubbha:issue8701@5.3.0

And while trying to create it I realized it all boils down to a script thowing within a Cypress.on('test:after:run'):

Cypress.on('test:after:run', (test) => {
  if (test.state === 'failed') {
    throw new Error('I am throwing')
  }
})

Originally this was adding screenshots to mochawesome reports for the failed tests.
In my case it throws because it was still trying to read env.RETRIES from cypress.json, but it could throw for any reason.
Wrapping it in a simple try/catch does help.

Also it doesn't even matter if retries are configured in cypress.json or not.

So I am not sure if it can still be considered a bug or just a thing to be aware of for the guys out there.

@bahmutov
Copy link
Contributor

bahmutov commented Sep 30, 2020

Yeah I can recreate the problem in https://github.com/cypress-io/cypress-test-tiny/tree/throw-after

/// <reference types="cypress" />
Cypress.on('test:after:run', (test) => {
  if (test.state === 'failed') {
    // https://github.com/cypress-io/cypress/issues/8701
    throw new Error('I am throwing')
  }
})

describe('page', () => {
  it('works', () => {
    cy.visit('https://example.cypress.io')
    cy.get('[class^="main-nav-link active"]').should('contain', 'ZZZ')
  })
})

The test fails, throws an error and keeps on spinning

image

By the way, even in a successful test where you throw from test:after:run does not finish

Cypress.on('test:after:run', (test) => {
  throw new Error('I am throwing')
})

describe('page', () => {
  it('works', () => {
    cy.visit('https://example.cypress.io')
  })
})

@bahmutov bahmutov added stage: ready for work The issue is reproducible and in scope type: bug internal-priority and removed stage: needs information Not enough info to reproduce the issue labels Sep 30, 2020
@bahmutov
Copy link
Contributor

I have not verified what happens if an error is thrown in other event callbacks

@kuceb kuceb changed the title Retries [still] hangs on failed assertions Tests hang when error thrown in test:after:run hook Sep 30, 2020
@kuceb kuceb changed the title Tests hang when error thrown in test:after:run hook Tests hang when error thrown in test:after:run listener Sep 30, 2020
@kuceb
Copy link
Contributor

kuceb commented Sep 30, 2020

Looks like this has always causes the spec to hang, even before retries. I'll take a look. Thanks for the reproducible

@kuceb kuceb changed the title Tests hang when error thrown in test:after:run listener Spec hangs when error thrown in test:after:run listener Sep 30, 2020
@cypress-bot cypress-bot bot added stage: work in progress and removed stage: ready for work The issue is reproducible and in scope labels Sep 30, 2020
@jennifer-shehane
Copy link
Member

Duplicate of #2271

@jennifer-shehane jennifer-shehane marked this as a duplicate of #2271 Oct 2, 2020
@jennifer-shehane jennifer-shehane added type: duplicate This issue or pull request already exists and removed internal-priority type: bug labels Oct 2, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 2, 2020

The code for this is done in cypress-io/cypress#8709, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 14, 2020

Released in 5.4.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v5.4.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Oct 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: duplicate This issue or pull request already exists
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants