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

Visiting a cross origin page with a cy.origin command with no cy commands may cause subsequent tests to hang. #21300

Closed
mjhenkes opened this issue May 2, 2022 · 5 comments · Fixed by #23297
Assignees
Labels
topic: cy.origin Problems or enhancements related to cy.origin command type: bug

Comments

@mjhenkes
Copy link
Member

mjhenkes commented May 2, 2022

Current behavior

Since we no longer wait for stability before ending a test test we may now end up in a race condition where an unload event initiated in a previous test will occur in a subsequent test, setting stability to false. If that load event happens for a cross origin page the test will hang, forever since stability won't be set back to true.

It was assumed that setting the iframes src to the about:blank page would cancel any current load events happening within the iframe, but the opposite appears to be true, if the iframe is currently loading

Desired behavior

The second test should not hang based on commands run in the first test.

I believe we have to options to fix this, one more extreme than the other.

  1. Wait for stability prior to loading the about blank page in sessions/index. To achieve stability here, we will have know which spec bridge to continue to listen too and persist that state between tests. Currently this is handled within tests by the latestActiveOriginPolicy state, but that is cleared between tests. See relevant event-manager lines

  2. Revert the change that allows us to proceed in the event manager regardless of stability and instead allow cy.visit to successfully load cross-origin pages. This requires more investigation, but would have the dual effects of making it less confusing to visit pages (you could visit a cross origin page prior to entering a cy.origin block and allow us to remove code around syncing stability as you could not exit the command queue without being stable. Any any commands run after a visit would have to run against the correct origin. The downside of this approach would be that again, we'd be waiting on stability before exiting mocha blocks (but we've seen what not waiting can do) and we'd have to error in cy.visits on load functions if someone attempts to run them against a cross origin url. On loads would also have to be setup prior to visiting.

Test code to reproduce

The following test can be used to reproduce this issue in the 'driver' package of the cypress repo. This is most easily reproduced on firefox, but has also been observed on chrome.

// The first test executes fast enough that the onunload event occurs at the beginning of the second test.
it.only('runs', () => {
  cy.visit('/fixtures/primary-origin.html')
  cy.get('a[data-cy="cross-origin-secondary-link"]').click()
  cy.origin('http://foobar.com:3500', () => {
    expect(true).to.equal(true)
  })
})

it.only('it hangs', () => {
  cy.log('you will not see me')
})

Cypress Version

9.6.0

Other

No response

@mjhenkes
Copy link
Member Author

mjhenkes commented Sep 8, 2022

This will be fixed by #23297

@rachelruderman
Copy link
Contributor

@mjhenkes awesome! In that case, I think it makes sense to unskip the skipped tests in #23297. You can find them by searching the codebase for

// TODO: fix flaky test https://github.com/cypress-io/cypress/issues/21300

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 15, 2022

The code for this is done in cypress-io/cypress#23297, 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 Sep 27, 2022

Released in 10.9.0.

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

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Sep 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic: cy.origin Problems or enhancements related to cy.origin command type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants