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

Cypress reports a timeout for a XHR request not made through Cypress #2592

Closed
mitar opened this issue Oct 11, 2018 · 11 comments
Closed

Cypress reports a timeout for a XHR request not made through Cypress #2592

mitar opened this issue Oct 11, 2018 · 11 comments
Labels
type: duplicate This issue or pull request already exists

Comments

@mitar
Copy link

mitar commented Oct 11, 2018

Current behavior:

It seems Cypress hooks into all XHR requests and if they take a long time (more than a minute, mine can take around 3 minutes) to respond, it terminates the connection and reports an error. This is even for requests made by my own app and not those made through Cypress (like cy.request and so on).

Desired behavior:

I think this hooking into all XHR requests should be optional. Moreover, I have not found any documentation about it. In timeouts configuration I can see timeouts for cy.request and other commands, but there is no mention about XHR requests made by the app itself.

Steps to reproduce:

  • Make an app which creates a XHR POST request to the server and server takes more than 3 minutes to respond.
  • My nginx server is also configured to not timeout.
  • During regular operation, there is no timeout.
  • But during testing with Cypress, there will be a timeout.

Versions

Cypress 3.1.0.

@mitar
Copy link
Author

mitar commented Oct 11, 2018

The error I get is:

<!DOCTYPE html>
<html>
<body>
  Cypress errored attempting to make an http request to this url:<br /><br />http://localhost/api/post<br /><br /><br />The error was:<br /><br />ESOCKETTIMEDOUT<br /><br /><br />The stack trace was:<br /><br />Error: ESOCKETTIMEDOUT<br />    at ClientRequest.<anonymous> (/home/mitar/.cache/Cypress/3.1.0/Cypress/resources/app/packages/server/node_modules/request/request.js:812:19)<br />    at Object.onceWrapper (events.js:314:30)<br />    at emitNone (events.js:105:13)<br />    at ClientRequest.emit (events.js:207:7)<br />    at Socket.emitTimeout (_http_client.js:722:34)<br />    at Object.onceWrapper (events.js:314:30)<br />    at emitNone (events.js:105:13)<br />    at Socket.emit (events.js:207:7)<br />    at Socket._onTimeout (net.js:402:8)<br />    at ontimeout (timers.js:469:11)<br />    at tryOnTimeout (timers.js:304:5)<br />    at Timer.listOnTimeout (timers.js:264:5)<br />
</body>
</html>
```

@mitar
Copy link
Author

mitar commented Oct 11, 2018

I removed the following lines and now my tests work perfectly. Is there a way to disable all that?

Increasing timeout in config values didn't help.

@mitar
Copy link
Author

mitar commented Oct 11, 2018

Oh, I still have to set "requestTimeout": 3600000 and "responseTimeout": 3600000 for this commenting-out to work. Otherwise Cypress thinks there is some cross-origin error.

@jennifer-shehane
Copy link
Member

@mitar Could you try this workaround to see if this resolves your issue? Curious if it is related. #2055 (comment)

@jennifer-shehane jennifer-shehane added the stage: awaiting response Potential fix was proposed; awaiting response label Oct 11, 2018
@mitar
Copy link
Author

mitar commented Oct 11, 2018

Update: It seems commenting out that and timeout increase does not always fix it. Or mostly it still does not fix it. So not sure why it worked for me the first time.

@jennifer-shehane jennifer-shehane added stage: needs information Not enough info to reproduce the issue and removed stage: awaiting response Potential fix was proposed; awaiting response labels Oct 11, 2018
@mitar
Copy link
Author

mitar commented Oct 11, 2018

Yes it does. This helps, but also the following change to config is required (not sure if both, but I used both): "requestTimeout": 3600000, "responseTimeout": 3600000.

So yes, it seems the proxy timeouts, this is one problem. And the other is that those not-mocked requests also depend on timeouts in the config. I think they should not.

Thanks for pointing out that patch.

@jennifer-shehane
Copy link
Member

@mitar I can understand the frustration with having to set an arbitrary timeout for the requests, but we feel it is good practice to maintain timeout configuration to ensure our users can set reasonable limits for how long their request should go out before defaulting to failed.

Also, the test has to stop eventually - the request has to timeout eventually. There are timeouts in most CI's that don't even allow processes to run beyond 10 mins without output.

I'm going to close this as a duplicate of #205

@jennifer-shehane jennifer-shehane added type: duplicate This issue or pull request already exists and removed stage: needs information Not enough info to reproduce the issue labels Oct 12, 2018
@mitar
Copy link
Author

mitar commented Oct 12, 2018

Sure, but it is not documented anywhere that those configuration options control also not-mocked requests. I would even suggest you have a different configuration option for not-mocked requests.

Moreover, Cypress.Server{enabled: false}) should, I believe, disable those timeouts as well.

@mitar
Copy link
Author

mitar commented Oct 12, 2018

responseTimeout | 30000 | Time, in milliseconds, to wait until a response in a cy.request(), cy.wait(), cy.fixture(), cy.getCookie(), cy.getCookies(), cy.setCookie(), cy.clearCookie(), cy.clearCookies(), and cy.screenshot() commands

@jennifer-shehane
Copy link
Member

I created a new issue in our docs to document that non-mocked requests use timeout options here: cypress-io/cypress-documentation#1046.

We would have to discuss the ability to disable timeouts. I'll bring it up this suggestion with the team.

@mitar
Copy link
Author

mitar commented Mar 11, 2019

In fact, I am not sure why this was closed as a duplicate of #205?

The important thing here is that I want to do end-to-end testing with using Cypress just to click on my UI, without any mocking or anything, but Cypress interferes with this and changes the behavior of my app. Which prevents from really knowing that my app will work correctly in production.

So I agree that every test case in the test suite should have a timeout, but I do not understand why every XHR request my app is making should have a timeout? If my test case waits for 5 minutes because I configure it to wait for 5 minutes, it is enough and my app's code should make sure it does its work in 5 minutes, even if this means waiting for 5 minutes for XHR to return.

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

2 participants