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

davidlgj opened this Issue Oct 18, 2012 · 7 comments


None yet

4 participants


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.

Do something like:

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

And a e2e tests like:

it('timeout test',function(){

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;
     }, 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.


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;
          }, timeout);

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

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


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

Now I see!
Thanks again.

@btford btford closed this Aug 24, 2013
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.


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

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 join this conversation on GitHub. Already have an account? Sign in to comment