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

Assertion keeps spinning after passing #3144

Closed
bahmutov opened this issue Jan 16, 2019 · 2 comments
Closed

Assertion keeps spinning after passing #3144

bahmutov opened this issue Jan 16, 2019 · 2 comments
Labels
type: duplicate This issue or pull request already exists

Comments

@bahmutov
Copy link
Contributor

Quite an esoteric test case, but shows some edge case in assertion state management

Cypress 3.1.4 on Mac

Source code in https://github.com/bahmutov/retry-task-demo just clone, install and run

I am retrying a function that calls either a simple async promise-returning function or a function that calls cy.task. In both cases little utility function retry checks the upcoming assertion to stop.

const getRandomNumber = () => {
  return new Cypress.Promise((resolve, reject) => {
    setTimeout(() => {
      const x = Cypress._.random(0, 50)
      console.log('resolving with %d', x)
      resolve(x)
    }, 10)
  })
}

const retry = fn => () => {
  return fn().then(value => {
    return cy.verifyUpcomingAssertions(
      value,
      {},
      {
        onRetry: retry(fn)
      }
    )
  })
}

it('retries task', () => {
  let counter = 0
  const limit = 100
  const printToTerminal = () => cy.task('print', (counter += 1), { log: false })

  // cypress-pipe does not retry Cypress chains
  // cy.document()
  //   // .pipe(printToTerminal)
  //   .should('equal', limit)

  cy.log('retrying task')
  cy.then(retry(printToTerminal)).should('equal', limit)

  cy.log('retrying async random number')
  cy.then({ timeout: 10000 }, retry(getRandomNumber)).should('equal', 10)
})

The getRandomNumber retries itself fine and stops, and the assertion is green.

The printToTerminal that calls cy.task runs, retries, passes - but the assertion is still spinning in the UI

retry-task

@Saibamen
Copy link
Contributor

Confirmed in Cypress 3.1.4 running on Win 10 both Chrome 71 and Electron 59

@jennifer-shehane jennifer-shehane added stage: ready for work The issue is reproducible and in scope stage: needs investigating Someone from Cypress needs to look at this and removed stage: ready for work The issue is reproducible and in scope labels Jan 23, 2019
@jennifer-shehane
Copy link
Member

Closing as duplicate of #2380

@jennifer-shehane jennifer-shehane added type: duplicate This issue or pull request already exists and removed stage: needs investigating Someone from Cypress needs to look at this labels Jul 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants