Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Setting a timeout on a $http request breaks e2e tests #1472

Closed
davidlgj opened this issue Oct 18, 2012 · 7 comments
Closed

Setting a timeout on a $http request breaks e2e tests #1472

davidlgj opened this issue Oct 18, 2012 · 7 comments

Comments

@davidlgj
Copy link

If you configure $http with a custom timeout e2e tests becomes very slow. A browser.navigateTo takes >30s. It looks like the outstandingRequestsCount isn't decremented properly and it waits the entire timeout before continuing, even though the request got a 200 OK ages ago.

ex.
Do something like:

$http.get(url,{ timeout: 10000 });

And a e2e tests like:

it('timeout test',function(){
  browser().navigateTo('/index.html');
});
@davidlgj
Copy link
Author

I think I found the problem, in the "createHttpBackend" function if timeout is set it will thenuse $browser.defer to execute it, but $browser.defer increases outstandingRequestsCount and is never properly canceled if the request doesn't time out, at least not in e2e tests. The code in question looks like this:

if (timeout > 0) {
    $browserDefer(function() {
        status = -1;
        xhr.abort();
     }, timeout);
}

I've been testing around a bit, and it looks like doing a $browser.defer.cancel when request successfully finishes seems to fix it for e2e tests at least, although I haven't tried it outside of the testrunner yet. I'll see if I can get time to do a proper fix and a pull request.

@craftgear
Copy link

Bump.

So how did you circumvent this problem?

I did following like this:

        var deferred = null; //add this line
        if (timeout > 0) {
          deferred = $browserDefer(function() { //add deferred
            status = -1;
            xhr.abort();
          }, timeout);
        }
      }


      function completeRequest(callback, status, response, headersString) {
        $browser.defer.cancel(deferred); //add this line

But I had no dice.
Any suggestions would be appreciated.

Thanks.

@davidlgj
Copy link
Author

Oh, I circumvented it by not using a timeout at all during testing.

@craftgear
Copy link

Now I see!
Thanks again.

@btford btford closed this as completed Aug 24, 2013
@btford
Copy link
Contributor

btford commented Aug 24, 2013

As part of our effort to clean out old issues, this issue is being automatically closed since it has been inactivite for over two months.

Please try the newest versions of Angular (1.0.8 and 1.2.0-rc.1), and if the issue persists, comment below so we can discuss it.

Thanks!

@mikkosuonio
Copy link

On Angular 1.0.8 my E2E tests are slow when using a timeout in $http calls.

@mikkosuonio
Copy link

The tests work without problems if I set a timeout for $http calls when running AngularJS 1.2.0-rc2.

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

No branches or pull requests

4 participants