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

Retry automatically on cy.visit, cy.request, server check #4013

Closed
flotwig opened this issue Apr 22, 2019 · 2 comments · Fixed by #4015
Closed

Retry automatically on cy.visit, cy.request, server check #4013

flotwig opened this issue Apr 22, 2019 · 2 comments · Fixed by #4015
Assignees

Comments

@flotwig
Copy link
Contributor

flotwig commented Apr 22, 2019

We should automatically retry some operations for the user, to mimic the behavior of a normal Chrome action.

The following code was used to test the scenarios against a real Chrome instance:

const http = require('http')
const debug = require('debug')('test')

const immediateServer = http.createServer((req, res) => {
    debug(`received ${req.method} ${req.url}`)
    req.socket.destroy()
})

immediateServer.listen(12345)

const afterHeadersServer = http.createServer((req, res) => {
    debug(`received ${req.method} ${req.url}`)
    res.writeHead(200)
    res.write('')
    setTimeout(() => req.socket.destroy(), 2000)
})

afterHeadersServer.listen(12346)

const midBodyServer = http.createServer((req, res) => {
    debug(`received ${req.method} ${req.url}`)
    res.writeHead(200)
    res.write('<html>')
    setTimeout(() => req.socket.destroy(), 2000)
})

midBodyServer.listen(12347)

Page visits

  • If the request fails before receiving data, wait 5s before retrying once. It looks like Chrome retries with a backoff of 30 seconds each time, but we likely don't want to wait this long - just try 3 times with the user's commandTimeout between each
  test received GET / +0ms
  test received GET / +34ms
  test received GET / +5s
  test received GET / +30s
  test received GET / +1m
  • If the request fails after receiving headers but before data is sent (second case), the behavior is the same as above, so we should do the same:
  test received GET / +0ms
  test received GET / +37ms
  test received GET / +5s
  test received GET / +30s
  test received GET / +1m
  • If the request ends mid-body, Chrome doesn't retry or consider it an error:
  test received GET / +0ms

XHRs

  • In all 3 cases, Chrome does not automatically retry a failed GET XHR:
  test received GET / +0ms
  • Chrome will also not automatically retry a failed POST XHR:
  test received POST / +0ms

Conclusion

  • Implement automatic retries on cy.visit() network errors before body is received, try 3 times with commandTimeout wait each time
  • Same for cy.request()
  • Retry baseurl check 3x, with backoff of 1s, 2s, 2s
  • Pass through network errors so Chrome's normal retry behavior kicks in too
@flotwig flotwig self-assigned this Apr 22, 2019
@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review and removed stage: work in progress labels May 6, 2019
@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels May 15, 2019
@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 15, 2019

The code for this is done in cypress-io/cypress#4015, 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 May 17, 2019

Released in 3.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant