aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/libs/rdbms/database/DatabaseMysqlBaseTest.php
Commit message (Collapse)AuthorAgeFilesLines
* More misc test cleanupDannyS7122020-12-241-776/+0
| | | | | | | | | * parent::setUp() should be first, and ::tearDown() should be last * Move tests that directly extend PHPUnit\Framework\TestCase to /unit Change-Id: I1172855c58f4f52a8f624e6d596ec43beb8c93ff
* rdbms: Fix DatabaseMysqlBase::streamStatementEnd() possibly failingThiemo Kreuz2019-11-081-0/+19
| | | | | | | | | | | | | | | | | If a string starts with "DELIMITER" but the word is *not* followed by a space, the code will set $this->delimiter to null, possibly resulting in all kinds of hard to track errors. Even more problematic: the preg_match was *not* case-insensitive, but the condition was. Which means that all non-uppercase "delimiter …" would result in the same error. I'm not sure if it's worth keeping the additional string comparison for performance reasons. Probably not. That comparison is slow as well, and preg_match is surprisingly fast (when the pattern is properly written, which it is). Change-Id: I33944b7a2410f77e67ce7450af0359a88d39f1aa
* rdbms: various cleanups to LoadBalancer::reallyOpenConnection()Aaron Schulz2019-10-111-0/+2
| | | | | | | | | | | | | | | | | | Move the DBO_TRX init logic out of Database::__construct() and into LoadBalancer since the later already handles setting and clearing this flag based on transaction rounds starting and ending. Add 'lazyMasterHandle', 'topologyRole', and 'topologicalMaster' parameters to Database::factory() and inject them via LoadBalancer all at once in order to avoid worrying about call order. Move some type casting code to Database::__construct(). Add IDatabase::getTopologyRole()/getTopologicalMaster(). Use constants for getLBInfo()/setLBInfo() for better usage tracking and typo resistance. Change-Id: I437ce434326601e6ba36d9aedc55db396dfe4452
* Merge "rdbms: Add (soft) type hints to DatabaseMysqlBaseTest"jenkins-bot2019-10-071-16/+26
|\
| * rdbms: Add (soft) type hints to DatabaseMysqlBaseTestThiemo Kreuz2019-09-231-16/+26
| | | | | | | | | | | | | | | | | | | | | | | | These type hints make it easier to follow the code paths and understand what code is actually under test here. A few of these tests appear to be misplaced, as they don't cover any code in the DatabaseMysqlBase class. This also makes all @covers tags absolute so more tools can understand them (e.g. PHPStorm doesn't). Change-Id: I43c69be994d6094239954ea662801c1e7e8e2e41
* | Begin cleaning up PHPUnit 4 code from testsMax Semenik2019-10-041-1/+0
| | | | | | | | | | | | | | This process will be broken up into several parts for reviewability. Bug: T192167 Change-Id: Ie415fd3308384a5ca2b3de24ba037785f8a3a714
* | tests: Replace PHPUnit's loose assertEquals(false) with assertFalse()Thiemo Kreuz2019-10-041-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | assertEquals( false, … ) still succeeds when the actual value is 0, null, an empty string, even an empty array. All these should be reported as a failure, I would argue. Note this patch previously also touched assertSame( false ). I reverted these. The only benefit would have been consistency within this codebase, but there is no strict reason to prefer one over the other. assertFalse() and assertSame( false ) are functionally identical. Change-Id: Ic5f1c7d504e7249002d3184520012e03313137b4
* | rdbms: fix active GTID filtering in DatabaseMysqlBaseAaron Schulz2019-09-251-2/+8
|/ | | | | | | | | | | | | | | In masterPosWait(), only $pos will have the known active domain/server set since it usually comes from getMasterPos(). However, the reference position, from getReplicaDB(), does not have the active domains set since querying gtid_domain_id on the replica would be incorrect and getting a connection to the master could be expensive. Remove obsolete hacks for jobs that used to store master positions. Also, use the regular Database::query() method for stylistic consistency. Bug: T224422 Change-Id: I41bbb9f337e46451aa17788dbd446db4a213a5a7
* Revert "rdbms: make LoadBalancer::reallyOpenConnection() handle setting DBO_TRX"Urbanecm2019-08-251-2/+0
| | | | | | | | | This reverts commit 45831e619c5e667ae1201bcdacfb8d4dcce10b41. Reason for revert: Caused beta not work at all. Bug: T231162 Change-Id: Icc5c1fa0dc01082a622641ad96c22c939cd56d48
* rdbms: make LoadBalancer::reallyOpenConnection() handle setting DBO_TRXAaron Schulz2019-08-241-0/+2
| | | | | | | | | | | | | | Make LoadBalancer::reallyOpenConnection() handle initializing DBO_TRX instead of Database::__construct(). Also: * Avoid having the "catch" block appear like it returns a half-constructed Database. * Use the variable name $conn instead of $db to be consistent throughout the class. Only send Database::__construct() parameters that it recognizes instead of mixing in setLBInfo() data. Change-Id: Iffc3d1d0713051a164adb51a4c4ee12e4ac887c3
* Revert "Separate MediaWiki unit and integration tests"Legoktm2019-06-131-0/+740
| | | | | | | | This reverts commit 0a2b996278e57a8b8c5377cd3a3eaa54f993d4a9. Reason for revert: Broke postgres tests. Change-Id: I27d8e0c807ad5f0748b9611a4f3df84cc213fbe1
* Separate MediaWiki unit and integration testsMáté Szabó2019-06-131-740/+0
| | | | | | | | | | | | | | | | | | | | | 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
* Add missing @covers to database related testsUmherirrender2019-02-011-1/+1
| | | | Change-Id: I370275bb6c5d456b73f6a5f782e231f16c2b0fbe
* rdbms: Database::selectDB() update the domain and handle failure betterAaron Schulz2018-10-101-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | LoadBalancer uses Database::getDomainId() for deciding which keys to use in the foreign connection handle arrays. This method should reflect any changes made to the DB selection. If the query fails, then do not change domain field. This is the sort of approach that LoadBalancer is expects in openForeignConnection(). Also, throw an exception when selectDB() fails. The db/schema/prefix fields of Database no longer exist in favor of just using the newer currentDomain field. Also: * Add IDatabase::selectDomain() method and made selectDB() wrap it. * Extract the DB name from sqlite files if not explicitly provided. * Fix inconsistent open() return values from Database subclasses. * Make a relationSchemaQualifier() method to handle the concern of omitting schema names in queries. The means that getDomainId() can still return the right value, rather than confusingly omitt the schema. * Make RevisionStore::checkDatabaseWikiId() account for the domain schema. Unlike d2a4d614fce09c, this does not incorrectly assume the storage is always for the current wiki domain. Also, LBFactorySingle sets the local domain so it is defined even in install.php. * Make RevisionStoreDbTestBase actually set the LoadBalancer local domain. * Make RevisionTest::testLoadFromTitle() account for the domain schema. Bug: T193565 Change-Id: I6e51cd54c6da78830b38906b8c46789c79498ab5
* Use PHP 7 "\u{NNNN}" Unicode codepoint escapes in string literals (part 2)Bartosz Dziewoński2018-06-041-8/+4
| | | | | | | This is a follow-up to Idc3dee3a7fb5ebfaef395754d8859b18f1f8769a containing some less trivial changes. Change-Id: Ia7af2c1d000307d43278cde4a246df413d4ef263
* Merge "rdbms: ignore inactive mysql GTIDs in replication position methods"jenkins-bot2018-04-121-14/+171
|\
| * rdbms: ignore inactive mysql GTIDs in replication position methodsAaron Schulz2018-04-041-14/+171
| | | | | | | | | | | | | | | | | | | | | | If it is known that master writes will use GTIDs with a certain domain and server ID, ignore other ones on masterPosWait(). This restores ceb7d61ee except it uses the same server variables and MySQLMasterPos preserves the active server/domain information across serialization. Change-Id: I1a4f143adcbec642966d7d1a55edb0f414a7f0c4
* | tests: Enable PHPUnit 4/6 compat layer in some tests that need itKunal Mehta2018-04-071-0/+1
|/ | | | Change-Id: I27a21fa9e97414fae02acbefb28011f0275cba63
* Revert "rdbms: make getMasterPos() ignore GTIDs outside of gtid_domain_id"Aaron Schulz2018-04-021-166/+14
| | | | | | | | This had a noticeable increase in LoadBalancer::doWait timeouts. This reverts commit ceb7d61ee7ef3edc6705abd41ec86b3afcd9c491. Change-Id: I7004d55a05c20f646f70d778d7b6496123e270a4
* rdbms: make getMasterPos() ignore GTIDs outside of gtid_domain_idAaron Schulz2018-03-221-14/+166
| | | | | | | | | | | | | | | * Filter out GTIDs with a domain that is not the one binlog events would be written to if the Database handle was given write queries. Likewise for the MariaDB server_id component. * Also improve MySQL GTID support to better match that of MariaDB. This covers position retrieval, replication waiting, and ranges in GTIDs (which are almost always present). * Make some MySQLMasterPos variables private by making use of accesors instead. * Store the gtids array keyed by domain ID for convenience. * Clean up dynamic call to static method. Change-Id: Ic6ab517bc8f200c968ff892ade69ad1b9394ab21
* rdbms: inject the mysql index name aliases into DatabaseAaron Schulz2018-03-121-0/+65
| | | | | | Also added LBFactory::setTableAlias() for consistency with this Change-Id: Ie49003ff8fd5b99f75db9fae8fe0a184444254d4
* rdbms: Restore test for Database::setFlag()Timo Tijhof2018-03-081-28/+0
| | | | | | | | | | Follows-up b4eb1feed05b5, which inadvertendly replaced the setFlag() test with the clearFlag() test. Also move the test to the DatabaseTest.php file given it's only executing and covering base class. Change-Id: I2f4ed6c4eeba845eb67013e1ab7d2b2bde863119
* Remove FakeDatabaseMysqlBase test classAaron Schulz2018-03-071-87/+18
| | | | | | Improve some flag tests that did not seem to test much Change-Id: Iecfc877645cc66cb696beb2b314a6d149745a530
* Introduce IDatabase::buildIntegerCastaddshore2018-03-071-0/+10
| | | | Change-Id: Ib24856d1ebe017ff07ae497972c764b4a3f3c7df
* rdbms: add missing hint check DatabaseMysqlBase::isInsertSelectSafeAaron Schulz2018-03-011-0/+94
| | | | | | This was lost when a bunch of other logic was split off in 671368a59e3 Change-Id: I3d3f744f8fce007ecf88cbd2c9f99918b06f0573
* rdbms: make DBMasterPos implement SerializableAaron Schulz2018-02-231-0/+15
| | | | | | | | | | | | | | | | | | ChronologyProtector uses these classes to briefly store positions and everytime the fields change then errors can happen when old values are unserialized and used. Use a simple two-element map format for serialized positions. The fields are recomputed back from the data map. Values from before this change will issue the warning "Erroneous data format for unserializing". To avoid that, bump the ChronologyProtector key version. Future field changes will not require this. This change should be deployed on all wikis at once. Bug: T187942 Change-Id: I71bbbc9b9d4c7e02ac02f1d8750b70bda08d4db1
* Merge "build: Updating mediawiki/mediawiki-codesniffer to 16.0.0"jenkins-bot2018-02-191-1/+1
|\
| * build: Updating mediawiki/mediawiki-codesniffer to 16.0.0Umherirrender2018-02-171-1/+1
| | | | | | | | Change-Id: I59b59f79bbf3ce4feff3b3a20c1c31bc16370531
* | rdbms: make DatabaseMysql::masterPosWait() handle inactive GTIDsAaron Schulz2018-02-161-0/+32
|/ | | | Change-Id: I543deef24f6cbf99094a4f3bee7cabe768fa221a
* rdbms: make MySQLMasterPos handle inactive GTIDsAaron Schulz2018-02-151-9/+61
| | | | Change-Id: I328142a9fe10bccb2717a0a392e0c50d0c070390
* rdbms: avoid "SHOW MASTER/SLAVE STATUS" queries in the GTID caseAaron Schulz2018-02-081-26/+41
| | | | | | | | | | The binlog file/pos where only being used in __toString() for the GTID case. Make that method use the GTID set instead and avoid querying the old-fashioned binlog fields all together in that case. The STATUS queries involve some global lock contention. Bug: T180918 Change-Id: I18123a702e4f554b87bf5f90017b248062e73049
* rdbms: make affectedRows() work more consistentlyAaron Schulz2018-01-301-0/+3
| | | | | | | | | * Update replace()/upsert() to combine the affected row count for the non-native case * Also make replace() atomic in the non-native case, similar to how upsert() already works Change-Id: I6c9bcba54eca6bcf4a93a9b230aaedf7f36aa877
* Use ::class to resolve class names in testsUmherirrender2018-01-261-2/+3
| | | | | | | This helps to find renamed or misspelled classes earlier. Phan will check the class names Change-Id: Ie541a7baae10ab6f5c13f95ac2ff6598b8f8950c
* Remove support for PHP extension 'mysql' (not mysqli!)Seb352018-01-171-1/+1
| | | | | | | | | This PHP extension was deprecated in PHP 5.5 and removed in PHP 7.0. The newer MySQL driver 'mysqli' is the default driver since MediaWiki 1.22 and 'mysql' was deprecated in MediaWiki 1.30. Bug: T120333 Change-Id: Icff7a63ab47ae1483de87ba6486945974699362b
* Use MediaWikiCoversValidator for tests that don't use MediaWikiTestCaseKunal Mehta2018-01-011-0/+3
| | | | Change-Id: I8c4de7e9c72c9969088666007b54c6fd23f6cc13
* Disallow setting DBO_IGNORE in Database for sanityAaron Schulz2017-11-291-0/+21
| | | | | | | | | | | In the off chance something called this, it would break all sorts of code that expects that either query result functions either succeed or throw an error. Callers are not expected to have to check if the result of a query is meaningful or false due to an error. Change-Id: I0b4fe1403f55a399ffd40817ed12f857087d6f83
* build: Updating mediawiki/mediawiki-codesniffer to 0.12.0Umherirrender2017-09-101-2/+2
| | | | Change-Id: Iefaae5043fa77d5d556c31079549dab8f61bd3ef
* rdbms: Refactor DatabaseTestTimo Tijhof2017-07-201-6/+6
| | | | | | | | | | | | | | | | | | | | | * Move DatabaseTest and DatabaseSQLTest to libs, and remove MediaWikiTestCase dependency. * Refactor DatabaseTest to be a test of the Database abstract class, not of whatever current DB backend is configured by LocalSettings. - Remove most switches/conditionals and other tests for specific database backends. Move those to individual test classes for those backends instead. - Some tests appear to have been integration tests for the PHP driver and/or the db backend itself. Moved to a new DatabaseIntegrationTest. - Now that only the abstract Database is invoked, the test runs a bit faster (no real connections/queries). * Add missing @covers tags, and remove or fix broken ones (follows-up 26e52f0c491a4). Change-Id: I9dc4a558e701d00e95789e7eb8e02926783b65ad
* rdbms: Move DatabaseMysqlBaseTest to libs testsTimo Tijhof2017-07-201-0/+371
* Remove MediaWikiTestCase dependency. * Add missing @covers tags. * Add missing visibility/static declarations. Change-Id: I2d81a9265016174e7b4ff810f140f7d031ce9f14