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

fix($http): include interceptors as a part of $browser's outstandingRequest #13862

Conversation

wbyoko
Copy link
Contributor

@wbyoko wbyoko commented 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.

Fixes #13782

$browser = browser;
}]));

it('should update $brower outstandingRequestCount', function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$brower --> $browser

gkalpak added a commit to gkalpak/angular.js that referenced this pull request Jan 28, 2016
This allows protractor to more reliably detect when all outstanding requests have been completed.

Fixes angular#13782
Closes angular#13862
@gkalpak gkalpak added this to the 1.5.x - migration-facilitation milestone Jan 28, 2016
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Jan 28, 2016
This allows protractor to more reliably detect when all outstanding requests have been completed.

Fixes angular#13782
Closes angular#13862
@wbyoko
Copy link
Contributor Author

wbyoko commented Jan 28, 2016

@gkalpak @Narretz Removed the changes to ngMock's $browser in favor of using spy. Also added a test for failure as well. Would you think more tests are needed?

@gkalpak
Copy link
Member

gkalpak commented Feb 1, 2016

@wbyoko, I was trying to reproduce the problem in an e2e test, but couldn't. Do you happen to have a minimal reproduction (even a flaky one) ?

@wbyoko
Copy link
Contributor Author

wbyoko commented Feb 1, 2016

This fiddle I included in #13782 shows the issue. http://jsfiddle.net/awtwff3x/

You could also use an interceptor with a setTimeout which resolves a promise.

We do have request interceptors in our project which may be why we would see this issue.

do you add e2e tests in test/e2e/tests ?

@gkalpak
Copy link
Member

gkalpak commented Feb 1, 2016

@wbyoko, thx (it seems like I missed that).

Regarding your question: One way to add e2e tests is to add a xyzSpec.js file in test/e2e/tests/ and a corresponding "tiny app" in test/e2e/fixtures/xyz/ (where you normally put an index.html and a script.js file). There is a sample you can take a look at.

@gkalpak
Copy link
Member

gkalpak commented Feb 2, 2016

@wbyoko, this test access $browser.notifyWhenNoOutstandingRequests() directly (i.e. without protractor).
Do you have any protractor tests that fail due to this issue ? I still can't reproduce it with protractor 😞

@wbyoko
Copy link
Contributor Author

wbyoko commented Feb 2, 2016

@gkalpak I added an e2e test. Uses the setTimeout method in an interceptor and doesn't pass without included updates to http.

I can clean this up and squash / recreate this commit. Would you think this e2e test is needed?

@wbyoko
Copy link
Contributor Author

wbyoko commented Feb 2, 2016

That test shouldn't pass on the master branch right now.

@gkalpak
Copy link
Member

gkalpak commented Feb 2, 2016

I'd like to have an actual e2e test that showcases the issue. Let me take a look and get back to you :)

@wbyoko
Copy link
Contributor Author

wbyoko commented Feb 2, 2016

@gkalpak Thanks. I ran this test on the master branch to make sure that it didn't pass.

And this showcases the fix by including interceptors as a part of the outstanding request which normally protractor wasn't waiting for.

I wouldn't understand how the e2e test is accessing $browser.notifyWhenNoOutstandingRequests() directly.

Thanks again.

@gkalpak
Copy link
Member

gkalpak commented Feb 2, 2016

Protractor uses $$testability.whenStable() to detect stability before performing any action (e.g. finding elements on a page etc). $$testability.whenStable() uses $browser.notifyWhenNoOutstandingRequests().

@wbyoko
Copy link
Contributor Author

wbyoko commented Feb 2, 2016

But with the e2e test it's going through protractor to do it.

So the fiddle calls it directly, the e2e test doesn't.

It seems actual issue is that $browser's outstandingRequest should be including interceptors because otherwise using them has the potentially to make e2e tests inconsistent.

Thanks.

@wbyoko
Copy link
Contributor Author

wbyoko commented Feb 4, 2016

@gkalpak any updates on what you found?

Thanks.

@petebacondarwin petebacondarwin modified the milestones: 1.5.1, 1.5.x - upgrade-facilitation Feb 4, 2016
@gkalpak
Copy link
Member

gkalpak commented Feb 4, 2016

@wbyoko, I didn't get a chance to properly look into it yet. I'll get back to this right after v1.5.0 is out (probably today), so we'll get it into v1.5.1.

@wbyoko
Copy link
Contributor Author

wbyoko commented Feb 9, 2016

@gkalpak sounds good. Let me know when you have looked at this.

Thanks.

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
@matsko matsko modified the milestones: 1.5.2, 1.5.3 Mar 18, 2016
@petebacondarwin petebacondarwin modified the milestones: 1.5.3, 1.5.4 Mar 25, 2016
@petebacondarwin petebacondarwin modified the milestones: 1.5.4, 1.5.5 Apr 14, 2016
@petebacondarwin petebacondarwin modified the milestones: 1.5.5, 1.5.6 Apr 18, 2016
@Narretz Narretz modified the milestones: 1.5.6, 1.5.7 May 27, 2016
@gkalpak gkalpak modified the milestones: 1.5.7, 1.5.8 Jun 15, 2016
gkalpak pushed a commit to gkalpak/angular.js that referenced this pull request 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 pull request 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants