resourceloader: Jobs created in request() should wait for executing modules
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 11 Sep 2015 05:20:54 +0000 (06:20 +0100)
committerKrinkle <krinklemail@gmail.com>
Fri, 11 Sep 2015 06:27:34 +0000 (06:27 +0000)
commite03165c3cde36f58ed4af883f91b854e88e5df43
tree71e8ea8f8fb28cf1d1ffbdb3a67f4f17e2d4ca5b
parentd5a7559f9928c2048a0917ee0add5a817a98da60
resourceloader: Jobs created in request() should wait for executing modules

Fix a regression from 6e903b94f2. It failed to update this code to account for
the new "executing" state.

This code was sometimes causing the job dependencies to be an empty array
when the module in question is currently being executed. As such the job
wasn't blocked by anything and happily run the next time a random module
invoked handlePending to run any jobs that have been satisfied.

Scenario:

* in-page RLQ: Page loads a module X that contains scripts and styles.
  - state=loading
* Module X is found in storage and implemented.
  - state=executing
* execute() adds styles to css buffer (which is asynchronous).
  It provides a callback from which it would run the module's script, set
  to "ready", and trigger handlePending().
* in-page RLQ: The edit page uses 'mw.loader.using' to require module X
  and has a callback that uses the module.
* using() sees X is not already "ready", so it calls request() for X.
* request() creates a job for "X". It then wrongly filters out X from the list
  of modules to wait for. The filter is intended to remove modules that are
  complete (e.g. "ready", "error", or "missing"). After 6e903b94f2, it also
  removed anything with state "executing". This resulted in a job with
  an empty dependency list (nothing to wait for).
* The callstack is finished. At some point the css buffer will call back.
  Some other module requested before X enters state "ready" and triggers
  handlePending(). It finds an left-over empty job with no dependencies
  and runs it. "It" being the callback of X â€“ eventhough X isn't ready.

The added test fails without the change in mediawiki.js.

Bug: T112232
Change-Id: I3cc0c282e68a37b9b3256b213508362734161655
resources/src/mediawiki/mediawiki.js
tests/qunit/suites/resources/mediawiki/mediawiki.test.js