Commit graph

21 commits

Author SHA1 Message Date
Derick A
35357ce3fe resourceloader: Dependency inject WANObjectCache into MessageBlobStore
Change-Id: I0f4c4e0e753574cf060331c944f44318eaca1fec
2020-02-12 22:16:42 +00:00
Max Semenik
48a323f702 tests: Add explicit return type void to setUp() and tearDown()
Bug: T192167
Depends-On: I581e54278ac5da3f4e399e33f2c7ad468bae6b43
Change-Id: I3a21fb55db76bac51afdd399cf40ed0760e4f343
2019-10-30 14:31:22 -07:00
Max Semenik
bc3878e33a Begin cleaning up PHPUnit 4 code from tests
This process will be broken up into several parts for reviewability.

Bug: T192167
Change-Id: Ie415fd3308384a5ca2b3de24ba037785f8a3a714
2019-10-04 14:19:05 -07:00
Timo Tijhof
d6dd6e4d72 resourceloader: Remove use of object registering in test suites
This was done as a "clever" shortcut to make sure tests a little
but shorter, but also made them less consistent with normal code.

Remove this in favour of 'class' or 'factory' options as needed.
Also remove a bunch of unneeded register() calls.

The tests cover everything affected by this change.

Side fix - isFileModule should reject modules with 'factory'
the same way it rejected raw objects and non-FileModule 'class'
cases already. This is now covered by tests as well.

Bug: T222637
Change-Id: I3996317dbcd780cc6e0f82c84e769c08a3fc42bb
2019-07-12 01:17:44 +00:00
Legoktm
4e35134f7a Revert "Separate MediaWiki unit and integration tests"
This reverts commit 0a2b996278.

Reason for revert: Broke postgres tests.

Change-Id: I27d8e0c807ad5f0748b9611a4f3df84cc213fbe1
2019-06-13 23:00:08 +00:00
Máté Szabó
0a2b996278 Separate MediaWiki unit and integration tests
This changeset implements T89432 and related tickets and is based on exploration
done at the Prague Hackathon. The goal is to identify tests in MediaWiki core
that can be run without having to install & configure MediaWiki and its dependencies,
and provide a way to execute these tests via the standard phpunit entry point,
allowing for faster development and integration with existing tooling like IDEs.

The initial set of tests that met these criteria were identified using the work Amir did in
I88822667693d9e00ac3d4639c87bc24e5083e5e8. These tests were then moved into a new subdirectory
under phpunit/ and organized into a separate test suite. The environment for this suite
is set up via a PHPUnit bootstrap file without a custom entry point.

You can execute these tests by running:
$ vendor/bin/phpunit -d memory_limit=512M -c tests/phpunit/unit-tests.xml

Bug: T89432
Bug: T87781
Bug: T84948
Change-Id: Iad01033a0548afd4d2a6f2c1ef6fcc9debf72c0d
2019-06-13 22:56:31 +02:00
Timo Tijhof
c9318edc2d resourceloader: Warn on ResourceLoader::construct without Config
The only remaining use of 'new ResourceLoader' is in tests, which have
been migrated in this commit to either passing the real config explicitly
(for integration tests), or by passing a HashConfig from a new
'getMinimalConfig' method which has only the keys required for the tests
to pass (e.g. avoid any ConfigExeption for unknown keys).

Also clean up some related code quality issues:

* Migrate wfScript() to $conf->get() so that the local Config is used,
  instead of implicitly using global variables. This isn't deprecated for
  MediaWiki generally, but done here to prepare ResourceLoader for becoming
  a standalone library.

* Remove mocking of 'CacheEpoch' config, this is no longer used anywhere
  in ResourceLoader.

* Change EmptyResourceLoader to use the minimal config by default and
  remove code duplication by calling the parent.

  Update the small number of uses that are integration tests, to explicitly
  pass in the live config as needed. And for the one case that tests the
  'startup' module, it no longer needs to register it manually given this
  is part of ResourceLoader::__construct() by default.

Bug: T32956
Change-Id: I127346fd530fa66f205156e545758b1c29d0fac0
2019-06-10 15:24:45 +00:00
Timo Tijhof
429c5acbfd resourceloader: Omit non-existent messages in MessageBlobStore
Previously, it was exporting the result of $msg->plain() regardless
of $msg->exists(). This meant that, client-side, via mw.message
the message would always make mw.Message#exists return true, even
if in fact it did not exist.

Bug: T221294
Change-Id: I77122777ddaaa2d43f8385df9292540a8d21b328
2019-04-19 00:28:17 +00:00
Timo Tijhof
853a291903 resourceloader: Improve test cases for MessageBlobStore
Move source code to includes/resourceloader to match
test case. This is part of ResourceLoader and not meant
to be used elsewhere.

Merge two similar test cases for getting blobs and fetching
messages which were doing the same thing.

Rewrite the test names to be a better reflection of the stories
they test, add comments for why, and re-order them to put related
tests together.

Move test-utilities to the bottom and make them actually private.

Change-Id: I7a437eebf3ba6a722e286dfe77c2f9fe49ad222f
2019-03-27 23:53:23 +00:00
Timo Tijhof
3edaa0b37c resourceloader: Make $rl parameter mandatory for MessageBlobStore
Change-Id: I851b2417b7e495a1d0c7ee1aa8be2b2e970840bb
2019-02-19 17:16:57 +00:00
Aaron Schulz
46a43d8187 Fix flaky MessageBlobStoreTest assertion failures
Bug: T176097
Change-Id: I0f1e9a6a73bb5b2bc54ee400c5710055e992c3f1
2018-06-12 02:15:10 +00:00
Timo Tijhof
16663db53a resourceloader: Re-enable testGetBlobCached() test case
Unable to reproduce the failure locally with Quibble.

The failure never made sense to begin with, as the only thing I could
conclude after ruling out all other possibilities was that PHP was
somehow forgetting/losing a key in a plain array in HashBagOStuff.

Bug: T176097
Change-Id: Ia438d5a929d7bd5dccf09387980ba92207616db0
2018-06-05 17:57:51 +00:00
Timo Tijhof
353f09fac9 resourceloader: Disable a flaky MessageBlobStoreTest case
Sometimes fails on the mediawiki-phpunit-php70-jessie job.

Bug: T176097
Change-Id: Id8c142954d597e1efaa326795f419d48b7af8bdf
2018-04-17 22:19:36 +01:00
Umherirrender
63d96c15fd build: Updating mediawiki/mediawiki-codesniffer to 16.0.0
Change-Id: I59b59f79bbf3ce4feff3b3a20c1c31bc16370531
2018-02-17 13:29:13 +01:00
Umherirrender
45da581551 Use ::class to resolve class names in tests
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: Ie541a7baae10ab6f5c13f95ac2ff6598b8f8950c
2018-01-26 22:49:13 +01:00
Kunal Mehta
75160bdd3b Use MediaWikiCoversValidator for tests that don't use MediaWikiTestCase
Change-Id: I8c4de7e9c72c9969088666007b54c6fd23f6cc13
2018-01-01 08:28:02 +00:00
Gergő Tisza
525bfbc8df Switch to librarized version of TestingAccessWrapper
Replaces \TestingAccessWrapper (defined in core) with
\Wikimedia\TestingAccessWrapper (defined in the composer package
wikimedia/testing-access-wrapper).

See https://gerrit.wikimedia.org/r/#/q/topic:librarize-testing-access-wrapper
for downstream patches.

The core version of the class is kept around for a while to avoid
circular dependency problems.

Bug: T163434
Change-Id: I52cc257e593da3d6c3b01a909e554a950225aec8
2017-04-20 14:15:57 +00:00
Timo Tijhof
1c200d7682 resourceloader: Complete code coverage for MessageBlobStore
Change-Id: I6269843ed51c67bf2d300eb58a613122ffdae740
2017-03-31 17:58:43 -07:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Timo Tijhof
5d5b269e0e resourceloader: Migrate from msg_resource table to object cache
MessageBlobStore class:
* Make logger aware.
* Log an error if json encoding fails.
* Stop using the DB table. WANObjectCache supports everything we need:
  - Batch retrieval.
  - Invalidate keys with wildcard selects or cascading check keys.
* Update tests slightly since the actual update now happens on-demand as
  part of get() instead of within updateMessage().

ResourceLoader class:
* Remove all interaction with the msg_resource table. Remove db table later.
* Refactor code to use a hash of the blob instead of a timestamp.
  Timestamps are unreliable and roll over too frequently for message blob store
  because there is no authoritative source. The timestamps were inferred based on
  when a change is observed. Message overrides from the local wiki have an
  explicit update event when the page is edited. All other messages, such as
  from MediaWiki core and extensions using LocalisationCache, have a single
  timestamp for all messages which rolls over every time the cache is rebuilt.
  A hash is deterministic, and won't cause needless invalidation (T102578).
* Remove redundant pre-fetching in makeModuleResponse().
  This is already done by preloadModuleInfo() in respond().
* Don't bother storing and retreiving empty "{}" objects.
  Instead, detect whether a module's message list is empty at runtime.

ResourceLoaderModule class:
* Make logger aware.
* Log if a module's message blob was not preloaded.

cleanupRemovedModules:
* Now that blobs have a TTL, there's no need to prune old entries.

Bug: T113092
Bug: T92357
Change-Id: Id8c26f41a82597e34013f95294cdc3971a4f52ae
2015-12-08 14:02:38 +00:00
Timo Tijhof
a4fa0229c1 Add unit tests for MessageBlobStore
* Also added getBlob() and getBlobs() methods. These don't
  require passing ResourceLoader as argument.
  In preparation for T113092.

Change-Id: I3239c45f0243eca1eaf85bc53fca736e4c9a209c
2015-11-21 00:09:47 +00:00