On 8 May 2014, at 22:02, Irving Reid <irv...@mozilla.com> wrote:

> I've recently fought my way through a bunch of intermittent test
> failures in the Add-on Manager mochitest-browser suite, and there's a
> common anti-pattern where tests receive a Window callback, usually
> "unload", and proceed to do significant work inside that event handler
> (e.g. opening/closing/focusing other windows; see one detailed case at
> https://bugzilla.mozilla.org/show_bug.cgi?id=608820#c281).
> 
> The 'unload' event is signalled before the window is completely
> unloaded; I don't know the fine details but the stack is in a state
> where other window operations sometimes fail.
> 
> Specifically, I found it a bit surprising that the "run_next_test()"
> function in the async test harness starts the next test immediately on
> top of the current JS stack, inside whatever callbacks are currently in
> progress.
> 
> I just filed bug 1007906 proposing that we modify the run_next_test
> function in the mochitest framework to always schedule the next test for
> a future spin of the event loop, to allow the stack to unwind - the
> xpcshell test harness already does this, see
> http://dxr.mozilla.org/mozilla-central/source/testing/xpcshell/head.js#1443.
> 
> We should also update the MDN documentation about writing mochitests to
> strongly advise making all DOM and Window callback listeners as small as
> possible; my preference is to advocate using Promises as callback
> listeners, because stack is always unwound before the .next handler is
> invoked.

It looks like a good place to put this information would be as a subsection of

https://developer.mozilla.org/en/docs/Mochitest#Writing_tests

Can you add in a brief section covering this point, along with a brief code 
snippet illustrating a good and a bad way to do it perhaps?

Just some rough notes would be fine; I’d be happy to edit it afterwards.

Many thanks,

Chris Mills
   Senior tech writer || Mozilla
developer.mozilla.org || MDN
   cmi...@mozilla.com || @chrisdavidmills



_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to