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

$http doesn't immediately increment $brower's outstandingRequestCount. Protractor issues result. #13782

Closed
wbyoko opened this issue Jan 17, 2016 · 2 comments

Comments

@wbyoko
Copy link
Contributor

wbyoko commented Jan 17, 2016

http://jsfiddle.net/awtwff3x/ (using Angular 1.4.8)

The issue is that using $http doesn't seem to register with $browser.defer synchronously so that $browser.notifyWhenNoOutstandingRequests waits accordingly.

This has created an issue where protractor tests are flaky because they aren't waiting for resources to load.

Also seems with $timeout registering synchronously using a $timeout anywhere in a controller will allow for the $http request to register and have the protractor test wait correctly.

You can uncomment line 22 to see that requests queue after $timeout is used, otherwise notifyWhenNoOutstandingRequests returns synchronously.

Thanks.

@petebacondarwin
Copy link
Contributor

I think this might be since we put the request through a $q promise that needs to be resolved async before the $httpBackend is triggered, right?

@petebacondarwin petebacondarwin added this to the 1.5.x - migration-facilitation milestone Jan 17, 2016
wbyoko added a commit to wbyoko/angular.js that referenced this issue Jan 27, 2016
The issue is that using $http doesn't update $browser.outstandingRequestCount synchronously so that $browser.notifyWhenNoOutstandingRequests waits accordingly.
Configuring this synchronization with the promise chain updates the outstandingRequestCount correctly.

Closes angular#13782
wbyoko added a commit to wbyoko/angular.js that referenced this issue Jan 27, 2016
The issue is that using $http doesn't update $browser.outstandingRequestCount synchronously so that $browser.notifyWhenNoOutstandingRequests waits accordingly.
Configuring this synchronization with the promise chain updates the outstandingRequestCount correctly.

Closes angular#13782
@wbyoko
Copy link
Contributor Author

wbyoko commented Jan 27, 2016

I have made pull requests for the 1.4 and master branches which fix this issue.

The $q promise needing to be resolved async is the issue and $browser.$$incOutstandingRequestCount() needed to be called synchronously. Configuring this and $browser.$$completeOutstandingRequest(noop) to respectively be before and at the end of the promise chain yields the correct result.

Tests to confirm this interaction were added and when implemented locally protractor waited accordingly.

@petebacondarwin petebacondarwin self-assigned this Jan 28, 2016
gkalpak added a commit to gkalpak/angular.js that referenced this issue Jan 28, 2016
This allows protractor to more reliably detect when all outstanding requests have been completed.

Fixes angular#13782
Closes angular#13862
gkalpak added a commit to gkalpak/angular.js that referenced this issue Jan 28, 2016
This allows protractor to more reliably detect when all outstanding requests have been completed.

Fixes angular#13782
Closes angular#13862
wbyoko added a commit to wbyoko/angular.js that referenced this issue Feb 10, 2016
The issue is that using $http doesn't update $browser.outstandingRequestCount synchronously so that $browser.notifyWhenNoOutstandingRequests waits accordingly.
Configuring this synchronization with the promise chain updates the outstandingRequestCount correctly.

Closes angular#13782
heathkit added a commit to heathkit/angular.js that referenced this issue Feb 20, 2016
Services such as $location and $http will initiate async calls. Thus,
we need to wrap the call to $browser.notifyWhenNoOutstandingRequest
in $timeout() in order to give any potentially outstanding async calls a
chance to run.

Fixes angular#13782
heathkit added a commit to heathkit/angular.js that referenced this issue Feb 20, 2016
Services such as $location and $http will initiate async calls. Thus,
we need to wrap the call to $browser.notifyWhenNoOutstandingRequest
in $timeout() in order to give any potentially outstanding async calls a
chance to run.

Fixes angular#13782
heathkit added a commit to heathkit/angular.js that referenced this issue Feb 20, 2016
Services such as $location and $http will initiate async calls. Thus,
we need to wrap the call to $browser.notifyWhenNoOutstandingRequest
in $timeout() in order to give any potentially outstanding async calls a
chance to run.

Fixes angular#13782
heathkit added a commit to heathkit/angular.js that referenced this issue Feb 23, 2016
Services such as $location and $http will initiate async calls. Thus,
we need to wrap the call to $browser.notifyWhenNoOutstandingRequest
in $timeout() in order to give any potentially outstanding async calls a
chance to run.

Fixes angular#13782
heathkit added a commit to heathkit/angular.js that referenced this issue Mar 14, 2016
Services such as $location and $http will initiate async calls. Thus,
we need to wrap the call to $browser.notifyWhenNoOutstandingRequest
in $timeout() in order to give any potentially outstanding async calls a
chance to run.

Fixes angular#13782
gkalpak pushed a commit to gkalpak/angular.js that referenced this issue Jul 15, 2016
…Count`

Calling `$http` will not increment `$browser.outstandingRequestCount` until after all (potentially)
asynchronous request interceptors have been processed and will decrement it before any (potentially)
asynchronous response interceptors have been processed.
This can lead to `$browser.notifyWhenNoOutstandingRequests` firing prematurely, which can be
problematic in end-to-end tests.

This commit fixes this, by synchronizing the increment/decrement operations with `$http`'s internal
interceptor promise chain.

Fixes angular#13782
Closes angular#13862
gkalpak pushed a commit to gkalpak/angular.js that referenced this issue Jul 15, 2016
…Count`

Calling `$http` will not increment `$browser.outstandingRequestCount` until after all (potentially)
asynchronous request interceptors have been processed and will decrement it before any (potentially)
asynchronous response interceptors have been processed.
This can lead to `$browser.notifyWhenNoOutstandingRequests` firing prematurely, which can be
problematic in end-to-end tests.

This commit fixes this, by synchronizing the increment/decrement operations with `$http`'s internal
interceptor promise chain.

Fixes angular#13782
Closes angular#13862
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.