★ wanayoo — archive 1999 https://github.com/angular/zone.js/pull/94Nouvelle recherche | Portail wanayoo
Skip to content
This repository has been archived by the owner. It is now read-only.

don't spawn child zones from the root zone automatically for callabacks + don't leak zones in async jasmine tests #94

Closed
wants to merge 11 commits into from

Conversation

@IgorMinar
Copy link
Member

@IgorMinar IgorMinar commented May 2, 2015

No description provided.

For now I'm not documenting this api.

I think it generally useful and harmless enough that it could be a public api.
@IgorMinar
Copy link
Member Author

@IgorMinar IgorMinar commented May 2, 2015

@mhevery can you please review this as well. especially these changes:

  • fix: don't fork new zones for callbacks from the root zone
  • fix: always run jasmine's done callbacks for async tests in jasmine's zone

The latter one should be something that anyone that writes jasmine tests for code using zones should be using. That means angular/angular repo and any angular app. This makes me quite sad.

@IgorMinar IgorMinar force-pushed the IgorMinar:root-zone-no-wrap branch 5 times, most recently from cc4ba63 to dc9e04b May 2, 2015
@IgorMinar
Copy link
Member Author

@IgorMinar IgorMinar commented May 2, 2015

for some reason saucelabs fails to provide us with FF37 at the moment. hopefully this is just a temp issue. feel free to rerun the build when you are reviewing this. it should pass all tests.

@IgorMinar
Copy link
Member Author

@IgorMinar IgorMinar commented May 2, 2015

@btford I'm not sure if test: Element#onclick should run only if env supports it change is correct. it might be a legit bug in which case we should file an new issue and merge this as is.

@vicb
Copy link
Contributor

@vicb vicb commented May 2, 2015

Isn't the 2nd commit (do not fork the root zone) a BC break ?
If yes we should probably:

  • merge all other fixes before & cut a last 0.4 release,
  • clearly state that in the comment,
  • create a 0.5.0 release with the BC breaks (there is also id numbering pending)
@vicb
Copy link
Contributor

@vicb vicb commented May 2, 2015

Great PR btw !

@vicb

This comment has been minimized.

Copy link

@vicb vicb commented on zone.js in bebb04d May 4, 2015

I'm not sure if this commit is right by itself ?

console.log(zone.isRootZone()); // true

setTimeout(function() {
  console.log(zone.isRootZone()); // false while I would expect true
}

IMO it would make more sense to squash this one with "fix: don't fork new zones for callbacks from the root zone"

This comment has been minimized.

Copy link
Owner Author

@IgorMinar IgorMinar replied May 4, 2015

this is because of a bug that I fixed in the later commit. currently we create new zones for all callbacks. even if no custom zone was installed.

This comment has been minimized.

Copy link

@vicb vicb replied May 4, 2015

this is because of a bug that I fixed in the later commit.

I'm only saying that without your later fix, this commit is buggy. That's why I think your should squash the commits (or change their order)

This comment has been minimized.

Copy link

@vicb vicb replied May 4, 2015

And may be add a test from my first comment above.

This comment has been minimized.

Copy link
Owner Author

@IgorMinar IgorMinar replied May 7, 2015

there are tests that test this behavior already. besides the setTimeout test will fail after the extraneous zone spawning is fixed. so I think it's good as is.

I also can't change the order because the next commit depends on this one.

and the last option to squash the two commits doesn't feel right since one adds a feature and the other fixes a bug with a breaking change.

I suggest keeping as is.

@btford
Copy link
Contributor

@btford btford commented May 4, 2015

RE: #94 (comment)

+1, we should try to cut a v0.4.x release, then get all this in, then release v0.5.

// global beforeEach to check if we always start from the root zone
beforeEach(function() {
expect(window.zone.isRootZone()).toBe(true);
});

This comment has been minimized.

@btford

btford May 4, 2015
Contributor

Missing EOL

This comment has been minimized.

@IgorMinar

IgorMinar May 7, 2015
Author Member

there is an eol


(function() {
// patch jasmine's it and fit functions so that the `done` callback always resets the zone
// to the jasmine zone, which should be the root zone.

This comment has been minimized.

@btford

btford May 4, 2015
Contributor

Link to GH issue/discussion

@btford
Copy link
Contributor

@btford btford commented May 4, 2015

LGTM other than the few cosmetic things.

@mhevery
Copy link
Member

@mhevery mhevery commented May 6, 2015

looks reasonable to me.

@vicb
Copy link
Contributor

@vicb vicb commented May 6, 2015

@btford @IgorMinar What about you (I can not) make a release out of master as of now and I integrate all those changes in the split PR (#82) and merge it so that I we can get 0.5 out (would be great if this can happen tomorrow) ?

@IgorMinar If you have no news about what's going on with FF, let's stick to the currently used version for now ? Have you asked sauce labs support ?

@IgorMinar
Copy link
Member Author

@IgorMinar IgorMinar commented May 7, 2015

I haven't had time to work on this. We should definitely upgrade FF since it's unlikely that anyone we care about is using the version we are testing against. Can you try to fiddle with it, maybe use slightly older version of FF?

I think the rest of the commits are good to go. I can merge those in tomorrow morning.

@vicb
Copy link
Contributor

@vicb vicb commented May 7, 2015

Can you try to fiddle with it, maybe use slightly older version of FF?

I could

I think the rest of the commits are good to go. I can merge those in tomorrow morning.

Not sure if it is valuable to merge them on top of master. What I would love to see is a release on the current master and then I'll merge my CJS PR and integrate your commits into there and then we cut a 0.5.

I've tried to reach you on hangout w/o success to discuss about this

@vicb
Copy link
Contributor

@vicb vicb commented May 7, 2015

@IgorMinar context: the CJS PR is required for angular2 VmTurnZone which I would love to be able to merge shortly.

IgorMinar added 4 commits May 2, 2015
BREAKING CHANGE: New child zones are now created only from a async task that installed a custom zone.

Previously even without a custom zone installed (e.g. LongStacktracesZone), we would spawn new
child zones for all asynchronous events. This is undesirable and generally not useful.

It does not make sense for us to create new zones for callbacks from the root zone since we care
only about callbacks from installed custom zones. This reduces the overhead of zones.

This primarily means that LongStackTraces zone won't be able to trace events back to Zone.init(),
but instead the starting point will be the installation of the LongStacktracesZone. In all practical
situations this should be sufficient.

Closes #92
… zone

If we don't, we are leaking zones because Jasmine executes async tests from within the done callback,
which means we never unwind the zone stack.

This causes various specs to fail if other specs run before them and build up a zone stack.

Closes #91
Now that we don't leak zone in between tests and root zone doesn't spawn child zones automatically
for all callbacks we need to wrap all async tests into a test zone.
@IgorMinar IgorMinar force-pushed the IgorMinar:root-zone-no-wrap branch 2 times, most recently from 93e995a to 9a1a7b9 May 7, 2015
IgorMinar added 2 commits May 2, 2015
I'm keeping Safari 7 in the mix since Safari 8 is available only on MacOS 10.10.

I'm also dropping all but Chrome from browserify tests, since those tests are not browser specific
and we just need to run them once.
@IgorMinar IgorMinar force-pushed the IgorMinar:root-zone-no-wrap branch from 9a1a7b9 to d6685a8 May 7, 2015
@vicb
Copy link
Contributor

@vicb vicb commented May 7, 2015

merged into #82 last commit excluded, should I cheery pick this one also ?

@IgorMinar
Copy link
Member Author

@IgorMinar IgorMinar commented May 7, 2015

@vicb you do want the sauce connect update, please cp that as well

in order to get ff37 from saucelabs we need selenium 2.45.0 that's why I'm upgrading both
@IgorMinar
Copy link
Member Author

@IgorMinar IgorMinar commented May 7, 2015

OMG. GREEN BUILD. THAT CAN'T BE TRUE!

@vicb please cp also the ff upgrade and you should be golden

@vicb
Copy link
Contributor

@vicb vicb commented May 8, 2015

GREAT !!!!

FF37 launches ok right now... but I'm still seeing the "expect" issue now :(

@@ -8,7 +8,7 @@ var zone = null;
function Zone(parentZone, data) {
var zone = (arguments.length) ? Object.create(parentZone) : this;

zone.parent = parentZone;
zone.parent = parentZone || null;

This comment has been minimized.

@vicb

vicb May 8, 2015
Contributor

Doesn't this invalidate a lot of tests ?
ie expect(window.zone.parent).toBeDefined(); to test if the zone is the root zone ?
I'll try to update to isRootZone

This comment has been minimized.

@vicb

vicb May 8, 2015
Contributor

Hum... it's a little more subtle: the root zone will not be forked on bind

This comment has been minimized.

@IgorMinar

IgorMinar May 8, 2015
Author Member

right. that's what this PR is doing and that's an intentional change :) see a few lines below.

This comment has been minimized.

@vicb

vicb May 8, 2015
Contributor

right. that's what this PR is doing and that's an intentional change :) see a few lines below.

And I think this is the right thing to do. The wrong part is not to have updated the tests ;)

@vicb
Copy link
Contributor

@vicb vicb commented May 8, 2015

Playing with fdescribe, I was abble to narrow down the expect issue to XMLHttpRequest

  fit('should work with onreadystatechange', function (done) {
    var req = new XMLHttpRequest();
    req.onreadystatechange = function () {
      expect(window.zone.parent).toBeDefined();
      done();
    };
    req.open('get', '/', true);
    req.send();
  });

That triggers the error, even locally:

ERROR [karma]: Error: 'expect' was used when there was no current spec, this could be because an asynchronous test timed out

As always the error was in the last file in the folder... took me 15+ iterations to found it :(

@vicb
Copy link
Contributor

@vicb vicb commented May 8, 2015

And the reason is: onreadystatechange is called multiple times !

@vicb
Copy link
Contributor

@vicb vicb commented May 8, 2015

OMG... DEEEP GREEEN !!! 😢

@IgorMinar
Copy link
Member Author

@IgorMinar IgorMinar commented May 8, 2015

req.onreadystatechange is called multiple times per the spec. so our test is not correct.

@vicb
Copy link
Contributor

@vicb vicb commented May 8, 2015

req.onreadystatechange is called multiple times per the spec. so our test is not correct.

fixed in my PR

@vicb
Copy link
Contributor

@vicb vicb commented May 8, 2015

merged via #82

@vicb vicb closed this May 8, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.