Commit graph

738 commits

Author SHA1 Message Date
Umherirrender
2e4ee47c3d Cleanup mixed space/tab line indent
Change-Id: I833052a656b1ce419c0929f6f0514f2a33c2c4cc
2021-09-04 00:52:31 +02:00
Aaron Schulz
2947b099db objectcache: make use of new modtoken field in SqlBagOStuff (ii)
Add a multi-primary mode option that supports MySQL DB setups
that use circular replication with STATEMENT formatted binlogs.
The `modtoken` column is only used when multi-primary mode is
explicitly enabled in configuration. The column is used by write
queries to determine the "winning" version of keys, with the goal
of approximating "Last-Write-Wins" eventual consistency.

Writes with different timestamps can be handled by picking the
one with the highest timestamp as the "winner". Writes with the
same timestamp, from different primary DBs, can be handled by
picking the one from the primary DB with the highest server_id.
Writes with the same token timestamp from the same primary DB can
be handled by picking the last write to appear in the binlog.
The delete() operation uses tombstones in multi-primary mode,
since there must be a key version to actually compare with the
versions from other operations.

Also:
* Remove "LOCK IN SHARE MODE" that was made obsolete by the
  CONN_TRX_AUTOCOMMIT flag. For the SQLite transaction case,
  it is serializable anyway.
* Simplified handleWriteError() to match handleReadError()
  and merged them into handleDBError().

Changes from d56a686f83:
* Keep using replace() for set() in non-multi-primary mode.
* Fix old encoding issues when incrementing keys with postgres.

Bug: T274174
Change-Id: I25b1278586f99fdace8f2a081f6f460f734e5d83
2021-08-20 19:23:39 -07:00
jenkins-bot
81c6f56c43 Merge "Revert "objectcache: make use of new modtoken field in SqlBagOStuff"" 2021-08-17 16:30:31 +00:00
Ladsgroup
0bd5cf3910 Revert "objectcache: make use of new modtoken field in SqlBagOStuff"
This reverts commit d56a686f83.

Reason for revert: T288998#7287717

Bug: T288998
Change-Id: Ia05b00a345335fe8bdd6041323c3abfa79ded169
2021-08-17 15:29:32 +00:00
jenkins-bot
372f4218b9 Merge "objectcache: BagOStuff::genericKeyFromComponents() empty component fix" 2021-08-12 01:45:25 +00:00
Aaron Schulz
f27367af09 objectcache: BagOStuff::genericKeyFromComponents() empty component fix
Empty leading components should still be colon separated. Although the
keyspace and collection should never be empty strings, it does not hurt
to handle that case anyway for safety.

Change-Id: Ic89acaf1fe5c34e58323b2913a9a26f973868590
2021-08-11 17:57:59 -07:00
Aaron Schulz
d56a686f83 objectcache: make use of new modtoken field in SqlBagOStuff
Add a multi-primary mode option that supports MySQL DB setups
that use circular replication with STATEMENT formatted binlogs.
The `modtoken` column is only used when multi-primary mode is
explicitly enabled in configuration. The column is used by write
queries to determine the "winning" version of keys, with the goal
of approximating "Last-Write-Wins" eventual consistency.

Writes with different timestamps can be handled by picking the
one with the highest timestamp as the "winner". Writes with the
same timestamp, from different primary DBs, can be handled by
picking the one from the primary DB with the highest server_id.
Writes with the same token timestamp from the same primary DB can
be handled by picking the last write to appear in the binlog.
The delete() operation uses tombstones in multi-primary mode,
since there must be a key version to actually compare with the
versions from other operations.

Also:
* Remove "LOCK IN SHARE MODE" that was made obsolete by the
  CONN_TRX_AUTOCOMMIT flag. For the SQLite transaction case,
  it is serializable anyway.
* Simplified handleWriteError() to match handleReadError()
  and merged them into handleDBError().

Bug: T274174
Change-Id: Icc5eff9a032dd3403b5718058f20e38f8ea84af5
2021-08-05 02:33:00 +01:00
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
James D. Forrester
df5eb22f83 Replace uses of DB_MASTER with DB_PRIMARY
Just an auto-replace from codesniffer for now.

Change-Id: I5240dc9ac5929d291b0ef1c743ea2bfd3f428266
2021-04-29 09:24:31 -07:00
DannyS712
260f4ea92c Move MimeAnalyzerTest under unit tests
Extends the base PHPUnit\Framework\TestCase
and does not need any integration

Change-Id: I221ffb9d2ed96e240ad1be7f11c311f95883d882
2021-04-23 21:53:55 +00:00
Daimona Eaytoy
535d7abf59 phpunit: Mass-replace setMethods with onlyMethods and adjust
Ended up using
  grep -Prl '\->setMethods\(' . | xargs sed -r -i 's/setMethods\(/onlyMethods\(/g'

special-casing setMethods( null ) -> onlyMethods( [] )

and then manual fix of failing test (from PS2 onwards).

Bug: T278010
Change-Id: I012dca7ae774bb430c1c44d50991ba0b633353f1
2021-04-16 20:15:00 +02:00
DannyS712
d638b0c2cf Move remaining ParamValidator tests to unit tests
Change-Id: I82d18a3c8a4c68c7456d5e5e4979d6445185f1c8
2021-04-15 14:51:39 +00:00
DannyS712
ec3d351c62 Move most ParamValidator tests to unit tests
No integration needed, except for maybe in
the tests for the UploadedFile* classes, which
are left where they are for now - those tests
deal with the file system.

Change-Id: I4f38557d524b2d36dea36a926d0f31e1afed5c7a
2021-04-14 23:57:20 +00:00
DannyS712
438b3924b4 Reset fake timestamps for unit tests too
Discovered in another patch that while integration
tests automatically reset fake timestamps afterwards,
unit tests don't. Add a shared method to MediaWikiTestCaseTrait
to reset for both integration tests and unit tests

Do the same for TypeDefTestCase

Change-Id: I677aec4e60894053fc554f2e13b069fb599858f2
2021-04-14 21:01:33 +00:00
DannyS712
27eb31153f Move libs/rdbms/database tests to unit tests
No integration is needed
Also switch to extending MediaWikiUnitTestCase

Change-Id: I5d91e2de223a8dff9d61e8888778994d73e604df
2021-04-07 13:46:54 +00:00
Ammarpad
b6a3283047 Use MWMySQLPlatform class in test
Change-Id: I6adfd11378eefad3782760bd2586e763f530513a
2021-03-21 19:30:06 +01:00
jenkins-bot
faea8215d4 Merge "JPEG2000 MIME fixes" 2021-03-15 21:36:22 +00:00
Derk-Jan Hartman
114d8e1cc5 JPEG2000 MIME fixes
- jp2 is the preferred file extension
- add mime aliases
- add jpg/jpx (jpeg2000 part 2)
- add magic byte detection for both

Bug: T161934
Change-Id: I00f81d9c31bf53a3b950e8a1d2bf2684c3998745
2021-03-15 21:43:24 +01:00
DannyS712
2307aae4db TempFSFileIntegrationTest: put use statement at the top of the class
And add a line of documentation

Change-Id: I2a80be9ac1c011d5ecc5396d72bc2f24d1b1c420
2021-03-14 06:01:45 +00:00
DannyS712
2370cc7816 MimeAnalyzerTest: reduce duplication with a data provider
Change-Id: I40a6b956c3510ec67a85776b52437f8d96155fc2
2021-03-09 21:15:44 +00:00
DannyS712
05d7071712 Move libs/Message tests under unit tests
Do not rely on integration, and extends the base
PHPUnit\Framework\TestCase

Change-Id: Ib3d53e1611dbaa6c684c5393f94e7f199daa34d8
2021-03-01 15:56:50 +00:00
Timo Tijhof
245bdafd9e resourceloader: Add wikimedia/minify package and remove local copies
- JavaScriptMinifier: The public interface for this internal class is
  ResourceLoader::filter which, except for one caller (minify.php)
  is indeed consistently used already, no other callers need replacing.

- CSSMin: Idem for minification, however, this class has some other
  method as well, which have a number of internal users, but none
  outside core. These have all been replaced in this commit.

- Remove pear/net_url2 as own dependency as this was only used by CSSMin
  and recently added there. This is now a dependency of wikimedia/minify
  instead. This was not part of the public API and no longer mentioned
  here in composer.json or RELEASE-NOTES. (It remains pinned in
  mediawiki-vendor, however.)

Bug: T273247
Depends-On: Iadff8c2112d5e53bd994ab4882006e8c644a2379
Depends-On: Id3c6dcc0b952a9efe34b3a9ed88b716101a51f87
Depends-On: I589be910f57289fd908b22db87241b0e52da60d4
Change-Id: I8d71fc64aeecdb31db218b02e361ae9bb0d19b48
2021-02-24 21:03:02 +00:00
Ammarpad
2af69576e1 Tighten invalid timestamp error checking
Move ConvertibleTimestamp::getTimestamp call into try-block to catch
its exception.

While constructor of ConvertibleTimestamp does throw exception for
most invalid timestamps, it does not verify MediaWiki timestamp
length requirement as done by ::getTimestamp() method

Bug: T272637
Change-Id: Ia2c1887fba62870a5eafa28ec49ab5e631ca1d53
2021-02-11 11:26:54 +01:00
jenkins-bot
085f7d5c22 Merge "Make TypeDefTestCase::getInstance() abstract." 2021-02-09 08:46:29 +00:00
Umherirrender
a1de8b8700 Tests: Mark more more closures as static
Result of a new sniff I25a17fb22b6b669e817317a0f45051ae9c608208

Bug: T274036
Change-Id: I695873737167a75f0d94901fa40383a33984ca55
2021-02-09 02:55:57 +00:00
Reedy
eb41565a9a Tests: Start marking some closures as static
Bug: T274036
Change-Id: Ib738ecd3bc23d34900bc268c8246702ac3655746
2021-02-06 19:57:42 +00:00
Ammarpad
252fd6ff97 Make TypeDefTestCase::getInstance() abstract.
Required to be overriden by every subclass via direct override
or the indirect static property, which is used only for this
purpose.

The benefit of that is this automatically allow us to remove the
custom Logic exception/property null handling. It also obsoletes
the property itself, which is already a form of redundancy.

Additionaly it removes duplication in classes that are providing
the property and duplicating the base class method code, like
StringDefTest.php

It's better if every child class provide the needed instance via
consistent way and that which is not redundant with another.

Change-Id: Ibe10c2c01b381190cc92e7ee2e1e0888c16e5bf4
2021-02-06 12:31:00 +01:00
Umherirrender
393b6fb508 Add missing @param tags in tests
And exclude the rest inline to remove global exclude

Bug: T238572
Change-Id: Ib4c207177dd73702c113e6233f59be6e571a0f6a
2021-02-01 20:38:05 +01:00
Umherirrender
62002cdcf1 build: Update mediawiki/mediawiki-codesniffer to 35.0.0
Change-Id: Idb413be4b8cba8611afdc022af59810ce1a4531e
2021-01-31 13:34:38 +00:00
jenkins-bot
20eb747f6e Merge "mime: Make findMediaType() private (internal since 1.35)" 2021-01-28 18:10:59 +00:00
Thiemo Kreuz
b655f382db Remove broken/outdated @param/@throws tags from @dataProviders
My personal best practice is to not document @params when there
is a @dataProvider. I mean, these test…() functions are not
meant to be called from anywhere. They do not really need
documentation. @param tags don't do much but duplicate what the
@dataProvider does. This is error-prone, as demonstrated by the
examples in this patch.

This patch also removes @throws tags from tests. A test…() can
never throw an exception. Otherwise the test would fail.

Most of these are found by the not yet released I10559d8.

Change-Id: I3782bca43f875687cd2be972144a7ab6b298454e
2021-01-21 03:42:42 +00:00
Thiemo Kreuz
2f66b3754f tests: Remove @param docs from test code that just repeat the signature
These are not only 100% identical to the actual code, but also:
* It's error-prone. Some are already wrong.
* These test…() functions are not meant to be called from
  anywhere. What is the target audience for this documentation?
* There is a @dataProvider. What such @param tags actually do is
  document the provider, but in an odd place. Just looking at
  the provider should give the same information.
* The MediaWiki CodeSniffer allows to skip @param when there is
  a @dataProvider, for the reasone listed.

Change-Id: I0f6f42f9a15776df944a0da48a50f9d5a2fb6349
2021-01-21 03:41:23 +00:00
Timo Tijhof
8d71e83117 mime: Make findMediaType() private (internal since 1.35)
Only caller in 1 Gerrit-hosted extension (BlueSpiceUEModuleTable2Excel),
which is fixed in Iadfed3b5c5b249b00eb61f03296d6e223e422de8.

Change-Id: I0d3de862d592ae6ca3cbeeeb8d3f667a848273c2
2021-01-19 21:35:17 +00:00
DannyS712
6a93b0ca93 More misc test cleanup
* parent::setUp() should be first, and ::tearDown()
  should be last
* Move tests that directly extend PHPUnit\Framework\TestCase
  to /unit

Change-Id: I1172855c58f4f52a8f624e6d596ec43beb8c93ff
2020-12-24 00:52:06 +00:00
Reedy
b16a862d43 Upgrade doctrine/dbal from 2.10.4 to 3.0.0 for PHP 8.0 support
Some irritating breaking changes, including dropping PHP 7.2 support
and renaming the classes we care about. For now, hack in via || and
some back-compatibility class aliases.

Bug: T270732
Change-Id: I685f099584d2f0e5fa17f1f4275eab5289c7bfee
2020-12-23 02:24:31 +00:00
DannyS712
d464f84182 Fix a typo: matser -> master
Bug: T201491
Change-Id: I2230195439582b1977d0c84295a5e8d9ee07a6cf
2020-12-21 06:38:42 +00:00
jenkins-bot
8a53d3c2df Merge "objectcache: make BagOStuff key encoding more consistent" 2020-12-11 20:35:23 +00:00
Umherirrender
a04a649580 [UploadedFileStreamTest] Skip test with chmod
Change-Id: I361392cc139db1cf3ca071ec558f85594bdb49bc
2020-12-06 10:59:17 +00:00
Aaron Schulz
5c335f9d77 objectcache: make BagOStuff key encoding more consistent
Add "generic" key methods for quickly deriving keys from
key component lists in a bijective manor. This is useful
for BagOStuff classes that wrap other BagOStuff instances
or for parsing keys to get stats.

Make the proxy BagOStuff classes (ReplicatedBagOStuff,
MultiWriteBagOStuff, CachedBagOStuff) use "generic" keys
so that they can convert to appropriate keys when making
backing cache instance method calls.

Make EmptyBagOStuff, HashBagOStuff, APCUBagOStuff,
RedisBagOStuff, and RESTBagOStuff use "generic" keys rather
than those of MediumSpecificBagOStuff::makeKeyInternal().
This lets proxy BagOStuff classes bypass key conversions
when used with instances of these classes as backing stores.

Also:
* Fix missing incr(), incrWithInit(), and decr() return
  values in MultiWriteBagOStuff.
* Make MultiWriteBagOfStuff, ReplicatedBagOStuff, and
  CachedBagOStuff use similar backend method forwarding
  styles by using a new BagOStuff method.
* Improved various related bits of documentation.

Bug: T250239
Bug: T235705
Change-Id: I1eb897c2cea3f5b756dd1e3c457b7cbd817599f5
2020-12-02 20:20:42 -08:00
Timo Tijhof
af52ed44fd resourceloader: Fix malformed "https:/w/resources" mapping in CSSMin
Follows-up cd54c03e86, in which I forgot a call to setScheme()
in the `isServerLess` branch.

For "server-less" URLs, we mock both schema and host, but only
strip the host. This left something I did not think was allowed
in the Net_URL2 class, which is to produce a URL that has a full
protocol and scheme, no host, and then a full path.

Moreoever, not only is this allowed by the Net_URL2 class in PHP,
modern browsers Firefox and Chrome also actually support this
and interpret it as a "domain relative" (?) URL.

Bug: T268308
Change-Id: I26ed3e5e9a6922badd979bbe6f5588e319ec3ebb
2020-11-25 00:38:53 +00:00
Umherirrender
49efbfe2fb Improve documentation about object to be stdClass or specific type
Some classes still needs exclude for the sniff

Change-Id: I9536c2ee84f6fb4c83cf862a152cf6b00344cb97
2020-11-20 14:47:56 +00:00
jenkins-bot
661b421aa3 Merge "Fix GhostFieldAccessTrait tests" 2020-11-17 18:36:25 +00:00
jenkins-bot
3bcd7d6c8e Merge "In SelectQueryBuilder add "joins" as an alias for join_conds" 2020-11-17 17:26:22 +00:00
Tim Starling
e2431b632c In SelectQueryBuilder add "joins" as an alias for join_conds
Add "joins" as an alias for join_conds in queryInfo(). Make the name
configurable in getQueryInfo().

It's actually a very common convention, used in CommentStore, LocalFile,
RevisionStore, etc.

join_conds is still needed, since it's used in ApiQueryBase, QueryPage
and IndexPager. Also it's the name of the IDatabase::select() parameter.

Change-Id: I4034ba70e9651d7ff12c72d7d75f3f9e78ffe67a
2020-11-17 22:39:15 +11:00
jenkins-bot
d009d75c73 Merge "Start generateSchemaChangeSql.php" 2020-11-16 08:40:36 +00:00
jenkins-bot
32fed9c635 Merge "resourceloader: Remove wfExpandUrl() coupling from CSSMin" 2020-11-13 07:07:49 +00:00
jenkins-bot
f76cebdbfb Merge "Change SerializationTestTrait to call serializers inside tests" 2020-11-12 20:29:05 +00:00
Petr Pchelko
841476c223 Change SerializationTestTrait to call serializers inside tests
Methods called in @dataProvider are not counted in code coverage,
making an impression we are not covering serialization code.
Move calling the serializer/deserializer into some of the tests
to fix coverage reporting.

Change-Id: I014bdee94b7297f6d298a3fea91482674c666fe3
2020-11-12 08:58:13 -07:00
Petr Pchelko
2677811351 Fix GhostFieldAccessTrait tests
Change-Id: Id03febbcb9d250a649eb03006f4984d0fb38d8e5
2020-11-11 21:53:01 -07:00
jenkins-bot
a5dc8fa7ab Merge "objectcache: fix WANCache getWithSetCallback() when TTL < "lowTTL"" 2020-11-11 04:20:46 +00:00