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

waitForAngular isn't waiting for $http requests consistently (Pull Request Pending) #2954

Closed
wbyoko opened this issue Feb 17, 2016 · 4 comments

Comments

@wbyoko
Copy link

wbyoko commented Feb 17, 2016

I am having an issue where waitForAngular isn't waiting for $http requests in controllers. browser.sleep was used as an quick in-test fix initially.

I was able to identify a possible cause within angular.js where $http requests were not registering themselves synchronously with the $browser service as an outstanding request which caused $browser.notifyWhenNoOutstandingRequests (via angular.getTestability(el).whenStable(callback)) to return immediately and not wait for requests.

The change would be to register the $http request as an outstanding request immediately by moving that code from $httpBackend to $http.

In the project where I was having these issues this resolved them.

There is a pull request outstanding and would hope to get input from those on the protractor side as to whether this is an appropriate fix.

Should $http requests register as an outstanding request with the $browser service immediately?

This is the initial issue: angular/angular.js#13782

This is the pull request: angular/angular.js#13862

This is a fiddle showcasing that $http isn't registering synchronously: http://jsfiddle.net/awtwff3x/

Please ask questions if more explanation is needed; either here or on the pull request itself.

Thanks for your time.

@wbyoko wbyoko changed the title waitForAngular isn't waiting for $http requests consistently (angular 1.x) waitForAngular isn't waiting for $http requests consistently (Angular.js Pull Request Pending) Feb 19, 2016
@wbyoko wbyoko changed the title waitForAngular isn't waiting for $http requests consistently (Angular.js Pull Request Pending) waitForAngular isn't waiting for $http requests consistently (Pull Request Pending) Feb 19, 2016
@juliemr
Copy link
Member

juliemr commented Feb 19, 2016

@mgiambalvo and I think that we have a more general way to fix this - testability.whenStable should always run $browser.notifyWhenNoOustandingRequests asynchronously. This should give http a chance to register all requests with the backend first. We're testing that out now.

@wbyoko
Copy link
Author

wbyoko commented Feb 19, 2016

That sounds great!

There are definitely more way to fix this. That seems to be a possible solution as well.

Thank you for taking a look at this!

@heathkit
Copy link
Contributor

I'm going to proceed with the PR Julie mentioned, but it's worth pointing out that Protractor already effectively runs $browser.notifyWhenNoOustandingRequests asynchronously, since it only calls this from webdriver calls. The attached fiddle doesn't represent a situation that Protractor would ever encounter, since Protractor would never be calling $browser.notifyWhenNoOustandingRequests synchronously from within your application. The example app in #1641 is problematic for the same reasons.

It is possible there exists a situation where Protractor calls whenStable() when there are no outstanding http requests and there's a callback on the asyncQueue that will initiate one. However, I haven't been able to find a way for that to occur in Angular 1.5.1.

Is your issue consistent, or intermittent? Also, can you describe your app in more detail? Are you using ui-router? If you could produce an example app that demonstrates the problem when using Protractor, that would be very helpful. However, a more detailed description of when you're seeing this problem would probably suffice.

@juliemr
Copy link
Member

juliemr commented Jul 14, 2016

Closing as stale.

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