Closed Bug 874510 Opened 12 years ago Closed 7 years ago

[test-agent] Update mocha library (huge performance improvements)

Categories

(Firefox OS Graveyard :: Gaia::TestAgent, defect, P2)

x86_64
Linux
defect

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: salva, Assigned: julienw)

References

Details

(Keywords: perf, Whiteboard: [c=automation p= s= u=])

Attachments

(2 files, 6 obsolete files)

In Firefox, iframes are indexed inside the window object as window[0], window[1], ... one by iframe in the DOM. The mocha function filterLeaks() in charge of distinguish which global names are leaks and which not is not taking this in count so applications with iframes will report non-real memory leaks.
Salva, I think we don't want to modify a vendor library. The easiest way to workaround is to call |mocha.setup({ globals: ['0'] })| at the start of your test, see eg https://github.com/mozilla-b2g/gaia/blob/master/apps/sms/test/unit/thread_ui_test.js#L5
James, how do you feel about this ?
Flags: needinfo?(jlal)
I'm quite sure it will be closed, mine was (https://github.com/visionmedia/mocha/pull/820). But let's see :)
Oh, it was merged, congratulations ! Therefore we should maybe wait for a new version from them and use that new version. And maybe use your PR before that. I'll redirect the review to James then !
Comment on attachment 752259 [details] Prevent mocha library from considering iframes as leaks James is a better reviewer for this :)
Attachment #752259 - Flags: review?(felash) → review?(jlal)
Now that this in mocha lets update to v1.10 which should fix this issue.
Flags: needinfo?(jlal)
Attachment #752259 - Attachment is obsolete: true
Attachment #752259 - Flags: review?(jlal)
Comment on attachment 758634 [details] Pointer to Github pull request: https://github.com/mozilla-b2g/gaia/pull/10222 Thanks for upstreaming the fix! Here is a patch that updates our mocha to the latest version.
Attachment #758634 - Flags: review?(salva)
Comment on attachment 758634 [details] Pointer to Github pull request: https://github.com/mozilla-b2g/gaia/pull/10222 stealing, because I want this ;) one question in the PR
Attachment #758634 - Flags: review?(salva) → review?(felash)
Comment on attachment 758634 [details] Pointer to Github pull request: https://github.com/mozilla-b2g/gaia/pull/10222 r=me tried removing a mocha.globals call with numbers (which were triggered when adding iframes), and with this patch it works now. So cool, thanks Salva and James !
Attachment #758634 - Flags: review?(felash) → review+
since this is npotb I'd like to have this on v1-train too, could you uplift it once you'll merge it ?
James did the latest patch.
Assignee: salva → jlal
James, could we merge this please ?
Flags: needinfo?(jlal)
Looks like this is failing travis- I will take a look tomorrow morning.
Flags: needinfo?(jlal)
Flags: needinfo?(jlal)
I tried other travis runs : https://travis-ci.org/mozilla-b2g/gaia/builds/8453313 https://travis-ci.org/mozilla-b2g/gaia/builds/8454246 same behavior, but the second one is way stranger.
Assignee: jlal → nobody
Wow, I really thought we merged this... Taking to try to wrap this up next week.
Assignee: nobody → felash
Component: Gaia → Gaia::TestAgent
Tracing our mocha.js, I'm sure we haven't merge this yet. But mocha leaks didn't appear for a long time. So I think we can close this bug now :) On the other hand, our mocha version is too old and maybe it's time to update mocha for test-agent.
yeah we need to update mocha :) (see also bug 991663) We didn't see in a long time because we used "mocha.globals" to whitelist the iframes.
oh I found these mocha "globalIgnores" in test-agent at https://github.com/mozilla-b2g/gaia/blob/e51f41c910e5d27953f256a293cd0e9036359e33/dev_apps/test-agent/common/vendor/test-agent/test-agent.js#L3031 Bug was fixed by Michael Henretty in bug 867421. See also PR https://github.com/mozilla-b2g/gaia/commit/5d6623018670a7d5c4d37bf27bcb56395c3dfc4d#diff-28e938f73741aae68b3acb9d387d5132R2926 Because new version mocha has fixed this iframe leaks. So we could remove this workaround after upgrading mocha successfully. Let me close this bug. :)
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Ricky, sorry, I don't understand why you resolve/fixed the bug? We still didn't upgrade the mocha library?
Flags: needinfo?(ricky060709)
Sorry for doing this too quick. Because this bug has been fixed in this PR https://github.com/mozilla-b2g/gaia/commit/5d6623018670a7d5c4d37bf27bcb56395c3dfc4d#diff-28e938f73741aae68b3acb9d387d5132R2926 although mocha is still old but this workaround has given us an effect we want.
Flags: needinfo?(ricky060709)
ok, let me reopen then so that we remove this workaround and upgrade mocha :)
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Another vote for upgrading mocha. It's messing with the postMessage tests from bug 992193 (thanks Julien for finding it)
Blocks: 992193
Attached file github PR (obsolete) —
Attachment #758634 - Attachment is obsolete: true
Blocks: 1011587
So, with this PR, we see that an awful lot of test are breaking. The main difference is because how the new mocha is moving from one test to the next one. In the mocha lib we use now, it's using a postMessage as a 'nextTick' emulation. With the new lib, it uses a simple setTimeout call, which is really faster. And that's where most of the issues are: timing issues. Some unit tests are not reliable enough and are subject to timing issues. Here are the errors: https://travis-ci.org/mozilla-b2g/gaia/builds/25368412 I could fix one of them, the others are more difficult.
Current status: https://travis-ci.org/mozilla-b2g/gaia/builds/25393990 David, there are a lot of failure in the camera test, I tried to make sense of them but I don't know the app enough. Could you or someone from the media team possibly help here? One of the main change is that the "this" in suiteSetup/setup is not the same than in tests. I haven't checked exactly but I think the one in test() has the same properties, but copied from the parent.
Flags: needinfo?(dflanagan)
This cut the test suite in half (~20 minutes instead of 40), we should really land the new mocha as soon as possible. I think the strategy here is to open a bug for each application to fix the tests and then land the new mocha. Julien, do you mind opening those bugs?
Summary: [test-agent] The mocha library is considering iframes as leaks → [test-agent] Update mocha library (
Summary: [test-agent] Update mocha library ( → [test-agent] Update mocha library (huge performance improvements)
Julien, I'm not familar with the camera tests myself, but Wilson is. Wilson please see comment 28
Flags: needinfo?(dflanagan) → needinfo?(wilsonpage)
Another source of compatibility issues is with the mocha commit [1]. I made this change [2] to work around this change (another possibility would be to use a shared variable which would not depend on how mocha works internally). [1] makes nested suites inherit the context using prototype inheritance. That means that if you assign `this.variable` in a setup, then in the same setup or suiteSetup you make something with this variable, then in a nested suite you override it using `this.variable` again, the nested suite's `this.variable` is not the same object than the parent suite's `this.variable`. This can be worked around using a `this.state` object like in [2], or using shared variables instead. [1] https://github.com/visionmedia/mocha/commit/6c705cd4d4bde87d735fcf6d8726af720bf392a5 [2] https://github.com/julienw/gaia/commit/3060e61ed9d914ea5de7a440a18e01f60d10147a
Keywords: perf
Priority: -- → P2
Whiteboard: [c=automation p= s= u=]
julienw: I've fixed the camera unit-tests in my branch 'julienw-874510-upgrade-mocha'[1]. You can probably just cherry-pick my commit across onto your existing pull-request. I found the majority of the of the failure were related to SinonJS. As combination of `.useFakeTimers()` and `.callsArgAsync` seems to no longer work as it did. `.callsArgAsync` will no longer works when using fake-timers, requiring a `clock.tick(1)` call to. Anyway, seems all green now. [1]https://github.com/wilsonpage/gaia/tree/julienw-874510-upgrade-mocha
Flags: needinfo?(wilsonpage) → needinfo?(felash)
(In reply to Wilson Page [:wilsonpage] from comment #32) > julienw: I've fixed the camera unit-tests in my branch > 'julienw-874510-upgrade-mocha'[1]. You can probably just cherry-pick my > commit across onto your existing pull-request. > > I found the majority of the of the failure were related to SinonJS. As > combination of `.useFakeTimers()` and `.callsArgAsync` seems to no longer > work as it did. `.callsArgAsync` will no longer works when using > fake-timers, requiring a `clock.tick(1)` call to. A clear mocha bug from my point of view. I'll dig deeper and possibly report an issue there. Thanks so much for the investigation. Maybe it would make sense to have a separate bug and patch so that it can be reviewed by another peer?
It would also make sense to have a separate bug to land the fixes asap so that the patch doesn't bitrot while we wait for all the fixes.
Depends on: 1016393
Depends on: 1016407
Depends on: 1016410
(In reply to Julien Wajsberg [:julienw] from comment #33) > (In reply to Wilson Page [:wilsonpage] from comment #32) > > julienw: I've fixed the camera unit-tests in my branch > > 'julienw-874510-upgrade-mocha'[1]. You can probably just cherry-pick my > > commit across onto your existing pull-request. > > > > I found the majority of the of the failure were related to SinonJS. As > > combination of `.useFakeTimers()` and `.callsArgAsync` seems to no longer > > work as it did. `.callsArgAsync` will no longer works when using > > fake-timers, requiring a `clock.tick(1)` call to. > > A clear mocha bug from my point of view. > I'll dig deeper and possibly report an issue there. I tried every mocha version since callsArgAsync exists, and no version made this work (you can play with [1]). So something's missing in this explanation :) [1] http://jsbin.com/yiyegoqa/2/edit > > Thanks so much for the investigation. Maybe it would make sense to have a > separate bug and patch so that it can be reviewed by another peer? I filed several bugs for several apps. Current status (with Wilson's commit) is: https://travis-ci.org/mozilla-b2g/gaia/builds/26140588
Flags: needinfo?(felash)
Depends on: 1016429
Depends on: 1016431
Depends on: 1016432
Flags: needinfo?(jlal)
Depends on: 1024978
Depends on: 1019039
Depends on: 1026992
Depends on: 1027586
I think I'm fairly ready now. Rebased to latest master, added back all the travis jobs, and pushed. New travis run is: https://travis-ci.org/mozilla-b2g/gaia/builds/28036374
Comment on attachment 8423983 [details] [review] github PR Hey Yuren, please move forward and land yourself if the changes looks fine to you and both travis and gaia try looks right. Otherwise, I don't mind that you do the needed changes yourself when I'm away :)
Attachment #8423983 - Flags: review?(yurenju.mozilla)
Note that a run is about 8min faster with this change.
Hey Jonathan, with the changes in this pull request, the unit tests are failing in TBPL. I believe this is because we need node_modules for unit tests now, and we copy things in [1]. There is a dependency in both make test-agent-server and make test-agent-test, but this needs to be done before B2G-Desktop is launched, so maybe "make update-common" needs to be done explicitely on TBPL, with the same environment variables we use for the marionette-js tests ? Thanks for your help ! [1] https://github.com/mozilla-b2g/gaia/pull/19330/files#diff-b67911656ef5d18c4ae36cb6741b7965R790
Flags: needinfo?(jgriffin)
Yes, we'll need to add a call to self.make_node_modules() to the gaia_unit mozharness script, similar to what we do for gaia-integration: http://hg.mozilla.org/build/mozharness/file/ac8e4ce7775e/scripts/gaia_integration.py#l37 Keeping the needinfo for myself to remind me to do this.
Comment on attachment 8423983 [details] [review] github PR we should use update-common instead of common-install in GAIA/tests/travis_ci/unit-tests-in-firefox/install since this pr removed install-common in Makefile.
Attachment #8423983 - Flags: review?(yurenju.mozilla)
steal.
Assignee: felash → yurenju.mozilla
waiting travis & try server result.
(In reply to Jonathan Griffin (:jgriffin) from comment #45) > Yes, we'll need to add a call to self.make_node_modules() to the gaia_unit > mozharness script, similar to what we do for gaia-integration: > http://hg.mozilla.org/build/mozharness/file/ac8e4ce7775e/scripts/ > gaia_integration.py#l37 > > Keeping the needinfo for myself to remind me to do this. I'm trying this out on ash right now. I'm not sure it will be this simple, but maybe we'll be lucky.
Flags: needinfo?(jgriffin)
Landed a change to mozharness to make it install node modules the same way we currently do for gaia-integration tests: https://hg.mozilla.org/build/mozharness/rev/29a640b027ad I just retriggered the gaia-unit tests at https://tbpl.mozilla.org/?tree=Gaia-Try&rev=66ab96437b67d74a696eadf9d8079d458f19c7d0 to see if this will resolve the problem.
(In reply to Jonathan Griffin (:jgriffin) from comment #51) > Landed a change to mozharness to make it install node modules the same way > we currently do for gaia-integration tests: > > https://hg.mozilla.org/build/mozharness/rev/29a640b027ad > > I just retriggered the gaia-unit tests at > https://tbpl.mozilla.org/?tree=Gaia- > Try&rev=66ab96437b67d74a696eadf9d8079d458f19c7d0 to see if this will resolve > the problem. Oh this won't help us with gaia-try, since gaia-try uses a copy of mozharness from https: //hg.mozilla.org/users/jford_mozilla.com/mozharness
(In reply to Jonathan Griffin (:jgriffin) from comment #51) > Landed a change to mozharness to make it install node modules the same way > we currently do for gaia-integration tests: > > https://hg.mozilla.org/build/mozharness/rev/29a640b027ad > > I just retriggered the gaia-unit tests at > https://tbpl.mozilla.org/?tree=Gaia- > Try&rev=66ab96437b67d74a696eadf9d8079d458f19c7d0 to see if this will resolve > the problem. John, can you help merge this mozharness patch into the jhford_mozharness repo? I don't understand the state of that repo and don't want to mess anything up.
something here is In production
:jgriffin, can I merge my pr or should I wait your pr for mozharness?
Flags: needinfo?(jgriffin)
(In reply to Yuren [:yurenju] from comment #46) > Comment on attachment 8423983 [details] [review] > github PR > > we should use update-common instead of common-install in > GAIA/tests/travis_ci/unit-tests-in-firefox/install since this pr removed > install-common in Makefile. Actually, you can even remove the call because I adjusted the dependencies in the Makefile. See : https://github.com/mozilla-b2g/gaia/commit/2f17d91076c19f6c52ab69a4a42aa93ba26ce7fd#diff-12 (I don't know why I missed these changes in my latest squashed commit).
John, please see comment 53. Thanks !
Flags: needinfo?(jhford)
Stealing back now that I'm back :)
Assignee: yurenju.mozilla → felash
Comment on attachment 8423983 [details] [review] github PR Just pushed the missing changes in my PR.
Attachment #8423983 - Flags: review?(yurenju.mozilla)
I've updated my mozharness from hg.m.o/build/mozharness. Gaia-try will resume using regular /builds/mozharness as soon as possible.
Flags: needinfo?(jhford)
Depends on: 1032327
The latest push showed a remaining issue in the Settings app, so I filed bug 1032327 and provided a patch.
The mozharness bits seem to work now; Yuren's originally push to gaia-try now fails with: 10:46:52 INFO - JavaScript error: app://test-agent.gaiamobile.org/common/vendor/blanket/blanket.js, line 7396: mocha.reporter is not a function 10:46:53 INFO - JavaScript error: app://test-agent.gaiamobile.org/common/test/agent.js, line 69: TestAgent is not defined https://tbpl.mozilla.org/php/getParsedLog.php?id=42780403&tree=Gaia-Try&full=1
Hey Jonathan, we really need "make update-common", not only "make node_modules" :) "make update-common" will run "make node_modules" so you don't need to call it explicitely.
(In reply to Jonathan Griffin (:jgriffin) from comment #62) > The mozharness bits seem to work now; Yuren's originally push to gaia-try > now fails with: > > 10:46:52 INFO - JavaScript error: > app://test-agent.gaiamobile.org/common/vendor/blanket/blanket.js, line 7396: > mocha.reporter is not a function > 10:46:53 INFO - JavaScript error: > app://test-agent.gaiamobile.org/common/test/agent.js, line 69: TestAgent is > not defined > Actually, it's the same error than before :)
I'll try this out on cedar to make sure it doesn't break anything.
Attachment #8448176 - Flags: review?(felash)
Assignee: felash → jgriffin
(In reply to Jonathan Griffin (:jgriffin) from comment #65) > Created attachment 8448176 [details] [diff] [review] > Use make update-common instead of make node_modules, > > I'll try this out on cedar to make sure it doesn't break anything. On cedar, this patch fails with: 12:30:57 INFO - mkdir -p dev_apps/test-agent/common/vendor/test-agent/ 12:30:57 INFO - rm -f dev_apps/test-agent/common/vendor/test-agent/test-agent.js 12:30:57 INFO - rm -f dev_apps/test-agent/common/vendor/test-agent/test-agent.css 12:30:57 INFO - cp node_modules/test-agent/test-agent.js dev_apps/test-agent/common/vendor/test-agent/ 12:30:57 INFO - cp: cannot stat `node_modules/test-agent/test-agent.js': No such file or directory https://tbpl.mozilla.org/php/getParsedLog.php?id=42784750&tree=Cedar&full=1#error0
Assignee: jgriffin → felash
Flags: needinfo?(jgriffin)
Right, because it needs the new patch to work. Kind of chicken and egg. So, to break the evil circle, you can do both "make node_modules" first and only then "make update-common". It should work with both the current master (and thus the various branches) and the future master. Thanks for your work.
Flags: needinfo?(jgriffin)
Assignee: felash → jgriffin
Attachment #8448176 - Attachment is obsolete: true
Attachment #8448176 - Flags: review?(felash)
Flags: needinfo?(jgriffin)
(In reply to Jonathan Griffin (:jgriffin) from comment #68) > Created attachment 8448334 [details] [diff] [review] > Run 'make node_modules' then 'make update-common', This patch doesn't break on cedar.
Comment on attachment 8448334 [details] [diff] [review] Run 'make node_modules' then 'make update-common', Review of attachment 8448334 [details] [diff] [review]: ----------------------------------------------------------------- I don't feel competent to review patches for the test harness, especially that I don't really know how it works. As I understand, "make update-common" will be run for every test job that call the "make_node_modules" method. While it's not necessary (only the unit test harness uses it) it also doesn't do any harm (as it's not a slow operation). Adding a comment could be useful though, like: "This command copies the necessary files from node_modules to the test-agent's main directory."
Attachment #8448334 - Flags: review?(felash) → feedback+
Julien, I tried your pr and I got a test-agent webpage without any test cases, but it works on master, can you check that? > make clean && DEBUG=1 make && nightly -profile /home/yurenju/src/gaia/profile-debug app://test-agent.gaiamobile.org
Flags: needinfo?(felash)
Yuren, I think you need to run "make update-common" because this patch deletes some test-agent files in favor of copying them from node_modules. Both "make test-agent-test" and "make test-agent-server" run the "update-common" goal (using a Makefile dependency). This will remove the need to commit new versions of test-agent files each time we do a change. The inconvenient is that each time we'll change branches (from a moment before this patch to a moment after this patch) we'll need to run "make update-common".
Flags: needinfo?(felash)
My rationale for applying it to all Gaia jobs was that with the name "update-common", other logic may creep in that isn't unit-test specific. If that won't ever be the case, I'll change it just to run during gaia_unit tests.
Flags: needinfo?(felash)
Jonathan, I follow your rationale and honestly I don't know if that's true or wrong :) The name "update-common" comes from a time when we only had unit tests. I don't foresee that we'll use this goal for anything else (it didn't changed once in 2 years), but I may be wrong. In the end of the day, it doesn't really matter if it always runs or if it runs for unit tests only, so maybe better be safe?
Flags: needinfo?(felash)
Attached patch make.patch (obsolete) — Splinter Review
we should also make $(PROFILE_FOLDER) depend on update-common if DEBUG=1 since it will confuse if someone just wants open test-agent in browser for unit test without make test-agent-test or make test-agent-server.
discussed with Julien on IRC and because update-common depends on node-module and we don't want to $(PROFILE_FOLDER) depends on node-modules, we won't apply patch on comment 75 to julien's pr.
Comment on attachment 8423983 [details] [review] github PR okay then it looks good to me, r=yurenju thanks! and we have talked about an error message on test-agent, will you add in this pr or you will file another bug?
Attachment #8423983 - Flags: review?(yurenju.mozilla) → review+
I'll file a separate bug but mark this bug as a blocker bug. I'll wait for all dependencies to land before landing this. Thanks !
Depends on: 1033449
Assignee: jgriffin → felash
New status with the patch for bug 1032327: https://travis-ci.org/mozilla-b2g/gaia/builds/29308895 (Gaia-try seems to be off right now)
Depends on: 1035133
Travis is fine, but Gaia-try has more failures: https://tbpl.mozilla.org/?tree=Gaia-Try&rev=8dcacd7ad6f2
Depends on: 1069232
Depends on: 1069238
Blocks: 1070047
Depends on: 1070918
Depends on: 1073132
Depends on: 1073139
Depends on: 1073149
Depends on: 1073157
Depends on: 1073159
Depends on: 1073166
Blocks: 991663
Depends on: 1075475
Depends on: 1076169
Depends on: 1076231
Attached file github PR
Carrying over r=yurenju
Attachment #8423983 - Attachment is obsolete: true
Attachment #8444213 - Attachment is obsolete: true
Attachment #8498480 - Flags: review+
Depends on: 1085276
Hi! What's mocha version we used? BTW, mocha 2.0 was released a few days ago. https://github.com/mochajs/mocha/blob/master/History.md
I think we use mocha 1.7 for unit tests currently, given the history. For marionette tests we use mocha 1.20 (the one in package.json).
Firefox OS is not being worked on
Status: REOPENED → RESOLVED
Closed: 11 years ago7 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: