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

Allow configurable timeouts for page and XHR requests #2940

Closed
nestoru opened this issue Oct 7, 2018 · 17 comments
Closed

Allow configurable timeouts for page and XHR requests #2940

nestoru opened this issue Oct 7, 2018 · 17 comments
Assignees
Labels
SYSTEM: browser connection SYSTEM: hammerhead TYPE: enhancement The accepted proposal for future implementation.
Milestone

Comments

@nestoru
Copy link

nestoru commented Oct 7, 2018

Are you requesting a feature or reporting a bug?

Bug

What is the current behavior?

Any XHR that takes longer than 20 seconds will make tests depending on parsing the response fail

What is the expected behavior?

Either the page load ltimeout or another timeout should be available to make testcafe not fail when XHR take longer than 20 seconds

How would you reproduce the current behavior (if this is a bug)?

Run the below test which loads twp page that retrieve a simple JSON from a remote service using XHR. The first page XHR response returns in less than 1 sec. The second page XHR response returns in 25 seconds. The first succeeds but the second fails because testcafe gives up on XHR that take over 20 seconds.

import { Selector } from 'testcafe';

fixture `Testcafe XHR support POC`

test('the label jsonDisplay should show up the fast XHR response', async t => {
  // The below succeeds 
  await t.navigateTo('http://www.nestorurquiza.com/xhr.html');
  const jsonDisplay = Selector('#jsonDisplay').addCustomDOMProperties({
    innerHTML: el => el.innerHTML
  });
  await t.expect(jsonDisplay.visible).ok();
  await t.expect(jsonDisplay.innerHTML).contains('hello');
});

test('the label jsonDisplay should show up the slow XHR response', async t => {
  // The below fails
  await t.navigateTo('http://www.nestorurquiza.com/slowXHR.html');
  const jsonDisplay = Selector('#jsonDisplay').addCustomDOMProperties({
    innerHTML: el => el.innerHTML
  });
  await t.expect(jsonDisplay.visible).ok();
  await t.expect(jsonDisplay.innerHTML).contains('hello');
});

Using the following command the test ends with the below error:

$ ./node_modules/.bin/testcafe --selector-timeout 60000 --assertion-timeout 60000 --page-load-timeout 60000 chrome  tests/slow-xhr.test.js
 Running tests in:
 - Chrome 69.0.3497 / Linux 0.0.0

  XHR
 ✓ the label jsonDisplay should show up the fast XHR response
 ✖ the label jsonDisplay should show up the slow XHR response

   1) AssertionError: expected 'Result of request should appear here ...' to include 'hello'

      Browser: Chrome 69.0.3497 / Linux 0.0.0

         17 |  await t.navigateTo('http://www.nestorurquiza.com/slowXHR.html');
         18 |  const jsonDisplay = Selector('#jsonDisplay').addCustomDOMProperties({
         19 |    innerHTML: el => el.innerHTML
         20 |  });
         21 |  await t.expect(jsonDisplay.visible).ok();
       > 22 |  await t.expect(jsonDisplay.innerHTML).contains('hello');
         23 |});
         24 |

         at contains (/home/nurquiza/workspace/lms-e2e/tests/slow-xhr.test.js:22:41)



 1/2 failed (1m 05s)

Note that the command sets to 1 minute all the available timeouts. Optionally and for the record, see below the html of this page in case you want to host it yourself. Change the mocky-delay param to have a page to render in 1ms and another in 25s (If you host it you will need to either have the XHR service in the same sub-domain or provide CORS support for the remote service):

<html>
<head>
<title>XHR example</title>
</head>
<body>
<label id="jsonDisplay">Result of request should appear here ...</label>
<script>
const url = 'https://www.mocky.io/v2/5185415ba171ea3a00704eed?mocky-delay=1ms';
const jsonDisplay = document.querySelector('#jsonDisplay');
fetch(url).then(function(response) {
  response.text().then(function(text) {
    jsonDisplay.innerHTML = text;
  });
});
</script>
</body>

Provide the test code and the tested page URL (if applicable)

See above. Note that this is an issue that will result in tests suddenly not passing after a release just because the responses from the database are slower for instance. The test failure in that case becomes a distraction, a false positive.It would be ideal to have a configurable timeout for XHR responses or use the same page load timeout to fix the currently hardcoded 20 seconds landmark.

Specify your

  • operating system:
  • testcafe version:
  • node.js version:
$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.1 LTS"
$ ./node_modules/.bin/testcafe --version
0.20.3
$ node --version
v8.9.3

@miherlosev miherlosev added the STATE: Need clarification An issue lacks information for further research. label Oct 8, 2018
@AlexKamaev
Copy link
Contributor

I was able to reproduce the issue and prepared an example without calling any external sites' API.

Test page:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

<div id="jsonDisplay"></div>

<script>
    const url = 'http://127.0.0.1:8081?test=1';
    const jsonDisplay = document.querySelector('#jsonDisplay');
    fetch(url).then(function(response) {
        response.text().then(function(text) {
            jsonDisplay.innerHTML = text;
        });
    });

</script>
</body>
</html>

Test code

import { Selector } from 'testcafe';

const DestinationRequest = require('../../../../../../node_modules/testcafe-hammerhead/lib/request-pipeline/destination-request');

const http = require('http');

fixture `fixture`;

test('test', async t => {
    // DestinationRequest.TIMEOUT = 60000;

    const server = http.createServer((req, res) => {
        res.writeHead(200, {
            'Content-Type':                'text/json',
            'Access-Control-Allow-Origin': '*',
        });

        setTimeout(() => {
            res.write('hello');
            res.end();
        }, 40000);
    });

    server.listen(8081);

    await t.navigateTo(`http://127.0.0.1:8080/index.html`);

    await t.expect(Selector('#jsonDisplay').visible).ok();
    await t.expect(Selector('#jsonDisplay').textContent).contains('hello');

    // DestinationRequest.TIMEOUT = 25000;
});

You are right; the issue occurs when the server doesn't respond for a long period. This constant is defined in the testcafe core module testcafe-hammerhead https://github.com/DevExpress/testcafe-hammerhead/blob/master/src/request-pipeline/destination-request/index.js#L185
There is no public option to modify it, but it still can be modified. To make the example work, please uncomment all lines in the test file.

@AlexKamaev AlexKamaev reopened this Oct 8, 2018
@AlexKamaev AlexKamaev added TYPE: proposal and removed STATE: Need clarification An issue lacks information for further research. labels Oct 8, 2018
@AlexKamaev
Copy link
Contributor

I've discussed the issue with my colleagues and we decided that would be useful to have public options to set the timeout, so I'll mark the issue as proposal.

@nestoru
Copy link
Author

nestoru commented Oct 8, 2018

@AlexKamaev Thanks for the quick turnaround. Really appreciated.

@AndreyBelym AndreyBelym added TYPE: enhancement The accepted proposal for future implementation. and removed TYPE: proposal labels Feb 6, 2019
@AndreyBelym AndreyBelym added this to Error handling & Timeouts & Graceful degradation in Enhancements processing Mar 1, 2019
@AndreyBelym AndreyBelym changed the title testcafe will not work with AJAX (XHR) requests that take over 20 seconds testcafe will not work with AJAX (XHR) requests that take over 120 seconds Mar 11, 2019
@Farfurix
Copy link
Contributor

@AndreyBelym AndreyBelym changed the title testcafe will not work with AJAX (XHR) requests that take over 120 seconds Allow configurable timeouts for page and XHR requests Apr 19, 2019
@cericoli
Copy link

Any update on this at all? Very keen to see this implemented.

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label May 17, 2019
@AndreyBelym
Copy link
Contributor

@cericoli we haven't decided about the interface that can be used to modify such intrinsic values. We don't want to overwhelm regular users with excessive configuration details. Maybe we can introduce a section in the configuration file structure. But this problem still needs o lot of planning and development, so I can't give you any estimates.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label May 20, 2019
@zhkostadinov
Copy link

Team, are we going to have resolutions on that?

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Jan 21, 2020
@AlexKamaev
Copy link
Contributor

Currently, we do not have any news regarding this.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Jan 22, 2020
@zhkostadinov
Copy link

In this case, any workaround is highly appreciated.

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Jan 22, 2020
@alexey-lin
Copy link
Contributor

@zhkostadinov,
Did you try Alex' workaround from the first comment?

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Jan 23, 2020
@zhkostadinov
Copy link

The link which is posted leads to Page not found.
I suppose, he mentioned increasing the _defineProperty(DestinationRequest, "XHR_TIMEOUT", 2 * 60 * 1000); in file testcafe-hammerhead/lib/request-pipeline/destination-request/inex.js will solve that?
I already change the 2 * 60 * 1000 part to 200 * 60 * 1000, but it doesn't help me.
I'm using cli --assertion-timeout 150000, but it fails on the ~1 minute with that error.
The interesting thing is that, the error is observed when the test is running in parallel on Chrome(latest) and Firefox(latest). When I run the same tests only in Chrome, for example from 10 runs 3 will fail, the other will succeed.

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Jan 23, 2020
@Farfurix
Copy link
Contributor

@zhkostadinov

Hello,

Yes, you can change these timeouts:
lib/request-pipeline/destination-request/index.js

_defineProperty(DestinationRequest, "TIMEOUT", 25 * 1000);

_defineProperty(DestinationRequest, "XHR_TIMEOUT", 2 * 60 * 1000);

I'm using cli --assertion-timeout 150000, but it fails on the ~1 minute with that error.

The assertion timeout increase cannot fix the issue with the request.

Could you please share your simple project (or a public URL), so that we can reproduce the issue? We will examine it and check for a suitable solution.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Jan 24, 2020
@zhkostadinov
Copy link

Hello @Farfurix , thanks for the reply. Unfortunately, I'm not able to share that information, because it is for internal usage, and doesn't have a public part.

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Jan 24, 2020
@Farfurix Farfurix removed the STATE: Need response An issue that requires a response or attention from the team. label Jan 24, 2020
@miherlosev miherlosev self-assigned this Nov 9, 2020
@AndreyBelym AndreyBelym modified the milestones: Sprint #69, Sprint #70 Nov 25, 2020
@AndreyBelym AndreyBelym modified the milestones: Sprint #70, Sprint #71 Dec 15, 2020
Enhancements processing automation moved this from Error, Edge case handling & Timeouts & Graceful degradation to Closed Dec 21, 2020
@znar
Copy link

znar commented Feb 1, 2021

It changed:

const defaultTimeout = require('testcafe-hammerhead/lib/request-pipeline/destination-request/default-request-timeout'); 
defaultTimeout.page = 600000; 
// defaultTimeout.ajax = 1200000;

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Feb 1, 2021
@aleks-pro
Copy link
Contributor

Hello @znar ,

We've added an API that allows you to configure request timeouts: https://github.com/DevExpress/testcafe/blob/master/docs/articles/documentation/reference/command-line-interface.md#--ajax-request-timeout-ms.
It should be available in the next TestCafe release.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Feb 2, 2021
@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Feb 17, 2021
@AlexSkorkin AlexSkorkin removed the STATE: Need response An issue that requires a response or attention from the team. label Feb 18, 2021
@samplehub
Copy link

samplehub commented Sep 2, 2021

Any updates on this on latest release 1.5.3 ??

@aleks-pro , I am having the same issue. How to increase timeouts please?

TypeError: Cannot set property 'ajax' of undefined

Code is nt working

defaultTimeout.ajax = 10 * 60 * 1000;
defaultTimeout.page = 10 * 60 * 1000;

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Sep 2, 2021
@Farfurix
Copy link
Contributor

Farfurix commented Sep 3, 2021

@samplehub

Hello,

Please use the following API to configure your timeouts:

  1. --page-load-timeout-ms
  2. --ajax-request-timeout-ms
  3. --page-request-timeout-ms
  4. Test.timeouts Method

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Sep 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SYSTEM: browser connection SYSTEM: hammerhead TYPE: enhancement The accepted proposal for future implementation.
Projects
No open projects
Development

No branches or pull requests