Aaron Schulz has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/352992 )
Change subject: Fix some postgres test failures
......................................................................
Fix some postgres test failures
Bug: T75174
Change-Id: If9812ae301f0af84fa012e2e980b92036c1b29b2
---
M includes/libs/rdbms/database/DBConnRef.php
M includes/libs/rdbms/database/Database.php
M includes/libs/rdbms/database/DatabasePostgres.php
M includes/libs/rdbms/database/IDatabase.php
M tests/phpunit/includes/api/ApiQueryWatchlistIntegrationTest.php
M tests/phpunit/includes/db/LBFactoryTest.php
6 files changed, 50 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/92/352992/1
diff --git a/includes/libs/rdbms/database/DBConnRef.php
b/includes/libs/rdbms/database/DBConnRef.php
index c15572c..b6167aa 100644
--- a/includes/libs/rdbms/database/DBConnRef.php
+++ b/includes/libs/rdbms/database/DBConnRef.php
@@ -349,6 +349,10 @@
return $this->__call( __FUNCTION__, func_get_args() );
}
+ public function databasesAreIndependent() {
+ return $this->__call( __FUNCTION__, func_get_args() );
+ }
+
public function selectDB( $db ) {
return $this->__call( __FUNCTION__, func_get_args() );
}
diff --git a/includes/libs/rdbms/database/Database.php
b/includes/libs/rdbms/database/Database.php
index 3bb7e6a..3de86ac 100644
--- a/includes/libs/rdbms/database/Database.php
+++ b/includes/libs/rdbms/database/Database.php
@@ -1691,6 +1691,10 @@
return $field;
}
+ public function databasesAreIndependent() {
+ return false;
+ }
+
public function selectDB( $db ) {
# Stub. Shouldn't cause serious problems if it's not
overridden, but
# if your database engine supports a concept similar to MySQL's
diff --git a/includes/libs/rdbms/database/DatabasePostgres.php
b/includes/libs/rdbms/database/DatabasePostgres.php
index b92d072..5677300 100644
--- a/includes/libs/rdbms/database/DatabasePostgres.php
+++ b/includes/libs/rdbms/database/DatabasePostgres.php
@@ -99,13 +99,17 @@
);
}
+
$this->mServer = $server;
$this->mUser = $user;
$this->mPassword = $password;
$this->mDBname = $dbName;
$connectVars = [
- 'dbname' => $dbName,
+ // pg_connect() user $user as the default database.
Since a database is *required*,
+ // at least pick a "don't care" database that is more
likely to exist. This case
+ // arrises when LoadBalancer::getConnection( $i, [], ''
) is used.
+ 'dbname' => strlen( $dbName ) ? $dbName : 'postgres',
'user' => $user,
'password' => $password
];
@@ -165,11 +169,16 @@
return $this->mConn;
}
+ public function databasesAreIndependent() {
+ return true;
+ }
+
/**
* Postgres doesn't support selectDB in the same way MySQL does. So if
the
* DB name doesn't match the open connection, open a new one
* @param string $db
* @return bool
+ * @throws DBUnexpectedError
*/
public function selectDB( $db ) {
if ( $this->mDBname !== $db ) {
diff --git a/includes/libs/rdbms/database/IDatabase.php
b/includes/libs/rdbms/database/IDatabase.php
index ac9914b..bec26a6 100644
--- a/includes/libs/rdbms/database/IDatabase.php
+++ b/includes/libs/rdbms/database/IDatabase.php
@@ -1030,10 +1030,24 @@
public function buildStringCast( $field );
/**
+ * Returns true if DBs are assumed to be on potentially different
servers
+ *
+ * In systems like mysql/mariadb, different databases can easily be
referenced on a single
+ * connection merely by name, even in a single query via JOIN. On the
other hand, Postgres
+ * treats databases as fully separate, only allowing mechanisms like
postgres_fdw to
+ * effectively "mount" foreign DBs. This is true even among DBs on the
same server.
+ *
+ * @return bool
+ * @since 1.29
+ */
+ public function databasesAreIndependent();
+
+ /**
* Change the current database
*
* @param string $db
* @return bool Success or failure
+ * @throws DBConnectionError If databasesAreIndependent() is true and
an error occurs
*/
public function selectDB( $db );
diff --git a/tests/phpunit/includes/api/ApiQueryWatchlistIntegrationTest.php
b/tests/phpunit/includes/api/ApiQueryWatchlistIntegrationTest.php
index 0a2cd83..b508928 100644
--- a/tests/phpunit/includes/api/ApiQueryWatchlistIntegrationTest.php
+++ b/tests/phpunit/includes/api/ApiQueryWatchlistIntegrationTest.php
@@ -1475,6 +1475,9 @@
$this->watchPages( $otherUser, [ $target ] );
+ $reloadedUser = User::newFromName( $otherUser->getName() );
+ $this->assertEquals( '1234567890', $reloadedUser->getOption(
'watchlisttoken' ) );
+
$result = $this->doListWatchlistRequest( [
'wlowner' => $otherUser->getName(),
'wltoken' => '1234567890',
diff --git a/tests/phpunit/includes/db/LBFactoryTest.php
b/tests/phpunit/includes/db/LBFactoryTest.php
index 8b285cb..049f81f 100644
--- a/tests/phpunit/includes/db/LBFactoryTest.php
+++ b/tests/phpunit/includes/db/LBFactoryTest.php
@@ -409,16 +409,27 @@
"Correct full table name"
);
- \MediaWiki\suppressWarnings();
- $this->assertFalse( $db->selectDB( 'garbage-db' ) );
- \MediaWiki\restoreWarnings();
-
$this->assertEquals(
$this->quoteTable( $db, 'garbage-db' ) . '.' .
$this->quoteTable( $db, 'page' ),
$db->tableName( 'garbage-db.page' ),
"Correct full table name"
);
+ if ( $db->databasesAreIndependent() ) {
+ try {
+ $e = null;
+ $db->selectDB( 'garbage-db' );
+ } catch ( \Wikimedia\Rdbms\DBConnectionError $e ) {
+ // expected
+ }
+ $this->assertInstanceOf(
'\Wikimedia\Rdbms\DBConnectionError', $e );
+ $this->assertFalse( $db->isOpen() );
+ } else {
+ \MediaWiki\suppressWarnings();
+ $this->assertFalse( $db->selectDB( 'garbage-db' ) );
+ \MediaWiki\restoreWarnings();
+ }
+
$factory->closeAll();
$factory->destroy();
}
--
To view, visit https://gerrit.wikimedia.org/r/352992
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If9812ae301f0af84fa012e2e980b92036c1b29b2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits