Page MenuHomePhabricator

When CentralAuth is enabled, failing test files fail with a CentralAuth-related error rather than their actual failure
Closed, ResolvedPublic

Description

Since recently, I noticed that when tests fail locally, they fail with a CentralAuth-related error, rather than with the error that caused the actual issue. See this as an example (as of https://gerrit.wikimedia.org/r/c/mediawiki/extensions/GrowthExperiments/+/819657/7):

urbanecm@notebook  ~/unsynced/gerrit/mediawiki/extensions/GrowthExperiments
$ php ../../tests/phpunit/phpunit.php tests/phpunit/integration/Api/ApiManageMentorListTest.php
Using PHP 7.4.29
PHPUnit 8.5.26 #StandWithUkraine

EThere was 1 error:

1) GrowthExperiments\Tests\ApiManageMentorListTest::testWrongProvider
Wikimedia\Rdbms\DBQueryError: Error 1050: Table 'unittest_global_user_autocreate_serial' already exists
Function: Wikimedia\Rdbms\Database::sourceFile( /home/urbanecm/unsynced/gerrit/mediawiki/extensions/CentralAuth/includes/Hooks/Handlers/../../../schema/mysql/tables-generated.sql )
Query: CREATE TABLE `unittest_global_user_autocreate_serial` (
 uas_shard INT UNSIGNED NOT NULL,
 uas_value INT UNSIGNED NOT NULL,
 PRIMARY KEY(uas_shard)
 ) /*$wgDBTableOptions*/

 in /home/urbanecm/unsynced/gerrit/mediawiki/core/includes/libs/rdbms/database/Database.php:1810
Stack trace:
#0 /home/urbanecm/unsynced/gerrit/mediawiki/core/includes/libs/rdbms/database/Database.php(1794): Wikimedia\Rdbms\Database->getQueryException()
#1 /home/urbanecm/unsynced/gerrit/mediawiki/core/includes/libs/rdbms/database/Database.php(1768): Wikimedia\Rdbms\Database->getQueryExceptionAndLog()
#2 /home/urbanecm/unsynced/gerrit/mediawiki/core/includes/libs/rdbms/database/Database.php(1144): Wikimedia\Rdbms\Database->reportQueryError()
#3 /home/urbanecm/unsynced/gerrit/mediawiki/core/includes/libs/rdbms/database/Database.php(3765): Wikimedia\Rdbms\Database->query()
#4 /home/urbanecm/unsynced/gerrit/mediawiki/core/includes/libs/rdbms/database/Database.php(3700): Wikimedia\Rdbms\Database->sourceStream()
#5 /home/urbanecm/unsynced/gerrit/mediawiki/extensions/CentralAuth/includes/Hooks/Handlers/UnitTestsHookHandler.php(88): Wikimedia\Rdbms\Database->sourceFile()
#6 /home/urbanecm/unsynced/gerrit/mediawiki/core/includes/HookContainer/HookContainer.php(160): MediaWiki\Extension\CentralAuth\Hooks\Handlers\UnitTestsHookHandler->onUnitTestsAfterDatabaseSetup()
#7 /home/urbanecm/unsynced/gerrit/mediawiki/core/includes/HookContainer/HookRunner.php(3968): MediaWiki\HookContainer\HookContainer->run()
#8 /home/urbanecm/unsynced/gerrit/mediawiki/core/tests/phpunit/MediaWikiIntegrationTestCase.php(1761): MediaWiki\HookContainer\HookRunner->onUnitTestsAfterDatabaseSetup()
#9 /home/urbanecm/unsynced/gerrit/mediawiki/core/tests/phpunit/MediaWikiIntegrationTestCase.php(1709): MediaWikiIntegrationTestCase::setupTestDB()
#10 /home/urbanecm/unsynced/gerrit/mediawiki/core/tests/phpunit/MediaWikiIntegrationTestCase.php(474): MediaWikiIntegrationTestCase::setupAllTestDBs()
#11 /home/urbanecm/unsynced/gerrit/mediawiki/core/vendor/phpunit/phpunit/src/Framework/TestSuite.php(626): MediaWikiIntegrationTestCase->run()
#12 /home/urbanecm/unsynced/gerrit/mediawiki/core/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(659): PHPUnit\Framework\TestSuite->run()
#13 /home/urbanecm/unsynced/gerrit/mediawiki/core/vendor/phpunit/phpunit/src/TextUI/Command.php(235): PHPUnit\TextUI\TestRunner->doRun()
#14 /home/urbanecm/unsynced/gerrit/mediawiki/core/tests/phpunit/phpunit.php(101): PHPUnit\TextUI\Command->run()
#15 /home/urbanecm/unsynced/gerrit/mediawiki/core/tests/phpunit/phpunit.php(153): PHPUnitMaintClass->execute()
#16 {main}No tests executed!
PHP Fatal error:  Uncaught UnexpectedValueException: Got connection to 'awiki-unittest_', but expected local domain ('awiki') in /home/urbanecm/unsynced/gerrit/mediawiki/core/includes/libs/rdbms/loadbalancer/LoadBalancer.php:1157
Stack trace:
#0 /home/urbanecm/unsynced/gerrit/mediawiki/core/includes/libs/rdbms/loadbalancer/LoadBalancer.php(959): Wikimedia\Rdbms\LoadBalancer->getLocalConnection()
#1 /home/urbanecm/unsynced/gerrit/mediawiki/core/includes/libs/rdbms/loadbalancer/LoadBalancer.php(937): Wikimedia\Rdbms\LoadBalancer->getServerConnection()
#2 /home/urbanecm/unsynced/gerrit/mediawiki/core/includes/libs/rdbms/database/DBConnRef.php(65): Wikimedia\Rdbms\LoadBalancer->getConnectionInternal()
#3 /home/urbanecm/unsynced/gerrit/mediawiki/core/includes/libs/rdbms/database/DBConnRef.php(776): Wikimedia\Rdbms\DBConnRef->__call()
#4 /home/urbanecm/unsynced/gerrit/mediawiki/extensions/CentralAuth/includes/Hooks/Handlers/UnitTestsHookHandler.php(64): Wikimedia\Rdbms\DBConnRef->dropTable()
#5 /home/urbanecm/unsynced/gerrit/mediawi in /home/urbanecm/unsynced/gerrit/mediawiki/core/includes/libs/rdbms/loadbalancer/LoadBalancer.php on line 1157
urbanecm@notebook  ~/unsynced/gerrit/mediawiki/extensions/GrowthExperiments
$

As of the same GE patch, a different (passing) test works perfectly fine:

$ php ../../tests/phpunit/phpunit.php tests/phpunit/integration/Api/ApiQueryMentorMenteeTest.php 
Using PHP 7.4.29
PHPUnit 8.5.26 #StandWithUkraine                                                                                                                                                                                                                                                                                                                                                                                                  ....                                                                4 / 4 (100%)                                                                                                                                                                                                                                                                                                                                                  Time: 980 ms, Memory: 50.50 MB
OK (4 tests, 8 assertions)
You should really speed up these slow tests (>50ms)...
1. 68ms to run GrowthExperiments\\Tests\\ApiQueryMentorMenteeTest::testGetMenteesByName
urbanecm@notebook  ~/unsynced/gerrit/mediawiki/extensions/GrowthExperiments
$

ApiManageMentorListTest gives an more useful error message when executed with CentralAuth off:

urbanecm@notebook  ~/unsynced/gerrit/mediawiki/extensions/GrowthExperiments
$ php ../../tests/phpunit/phpunit.php tests/phpunit/integration/Api/ApiManageMentorListTest.php
Using PHP 7.4.29
PHPUnit 8.5.26 #StandWithUkraine

Time: 1.39 seconds, Memory: 54.50 MB

There was 1 failure:

1) GrowthExperiments\Tests\ApiManageMentorListTest::testNoPermissionsChange
Failed asserting that exception message 'You don't have permission to manage the list of mentors.' contains 'You don't have permission to enroll as a mentor.'.

/home/urbanecm/unsynced/gerrit/mediawiki/core/tests/phpunit/MediaWikiIntegrationTestCase.php:498
=== Logs generated by test case
[objectcache] [debug] MainWANObjectCache using store {class} {"class":"EmptyBagOStuff"}
[localisation] [debug] LocalisationCache using store LCStoreNull []
[MessageCache] [debug] MessageCache using store {class} {"class":"HashBagOStuff"}
[objectcache] [debug] MainWANObjectCache using store {class} {"class":"EmptyBagOStuff"}
[localisation] [debug] LocalisationCache using store LCStoreNull []
[UserOptionsManager] [debug] Loading options from database {"user_id":1}
[DeferredUpdates] [debug] DeferredUpdates::run: started MWCallableUpdate_MediaWiki\Extension\Notifications\Hooks::onUserSaveSettings #2482 []
[DeferredUpdates] [debug] DeferredUpdates::run: ended MWCallableUpdate_MediaWiki\Extension\Notifications\Hooks::onUserSaveSettings #2482, processing time: 0.00063180923461914 []
[localisation] [debug] LocalisationCache::isExpired(en): cache missing, need to make one []
[DeferredUpdates] [debug] DeferredUpdates::run: started CdnCacheUpdate #2488 []
[squid] [info] CdnCacheUpdate::purge: https://a.wikifarm.cz/wiki/User:UTSysop https://a.wikifarm.cz/w/index.php?title=User:UTSysop&action=history {"private":false}
[DeferredUpdates] [debug] DeferredUpdates::run: ended CdnCacheUpdate #2488, processing time: 9.7036361694336E-5 []
[localisation] [debug] LocalisationCache using store LCStoreNull []
[objectcache] [debug] MainWANObjectCache using store {class} {"class":"EmptyBagOStuff"}
[objectcache] [debug] MainObjectStash using store {class} {"class":"HashBagOStuff"}
[GrowthExperiments] [error] GrowthExperiments\Mentorship\Provider\GetMentorDataTrait::getMentorData failed to load mentor list: {error} {"error":"The configuration title does not exist.","impact":"No data about mentors can be found; wiki behaves as if it had no mentors at all"}
[GlobalTitleFail] [info] RequestContext::getTitle called with no title set. {"exception":{}}
[MessageCache] [debug] MessageCache using store {class} {"class":"HashBagOStuff"}
[localisation] [debug] LocalisationCache::isExpired(en): cache missing, need to make one []
===

FAILURES!
Tests: 13, Assertions: 32, Failures: 1.


You should really speed up these slow tests (>50ms)...
 1. 137ms to run GrowthExperiments\\Tests\\ApiManageMentorListTest::testAddPermissions with data set "only managementors"
 2. 73ms to run GrowthExperiments\\Tests\\ApiManageMentorListTest::testAddDefaultValues with data set "only weight"
 3. 72ms to run GrowthExperiments\\Tests\\ApiManageMentorListTest::testAddPermissions with data set "only enrollasmentor"
 4. 71ms to run GrowthExperiments\\Tests\\ApiManageMentorListTest::testAddDefaultValues with data set "none"
 5. 70ms to run GrowthExperiments\\Tests\\ApiManageMentorListTest::testAddPermissions with data set "both rights"
 6. 68ms to run GrowthExperiments\\Tests\\ApiManageMentorListTest::testAddDefaultValues with data set "only message"
 7. 68ms to run GrowthExperiments\\Tests\\ApiManageMentorListTest::testAddDefaultValues with data set "only autoassigned"
urbanecm@notebook  ~/unsynced/gerrit/mediawiki/extensions/GrowthExperiments
$

Version details:

urbanecm@notebook  ~/unsynced/gerrit/mediawiki/extensions/GrowthExperiments
$ git show --oneline -s HEAD
92ef54f1 (HEAD -> review/urbanecm/T314414) Grant "enrollasmentor" to users meeting community's criteria
urbanecm@notebook  ~/unsynced/gerrit/mediawiki/extensions/GrowthExperiments
$ cd ../CentralAuth
urbanecm@notebook  ~/unsynced/gerrit/mediawiki/extensions/CentralAuth
$ git show --oneline -s HEAD
76efd6a6 (HEAD -> master, origin/master, origin/HEAD) Localisation updates from https://translatewiki.net.
urbanecm@notebook  ~/unsynced/gerrit/mediawiki/extensions/CentralAuth
$ cd ../../core/
urbanecm@notebook  ~/unsynced/gerrit/mediawiki/core
$ git show --oneline -s HEAD
89dc14bc60 (HEAD -> master, origin/master, origin/HEAD) Merge "Parsoid Parser Tests: Fix test processing to update knownFailures"
urbanecm@notebook  ~/unsynced/gerrit/mediawiki/core
$

Event Timeline

Restricted Application added subscribers: Base, Aklapper. · View Herald Transcript

The table was added in rECAUd4289d11dc4c: Support for temporary user creation recently, as part of the IP masking / temp user work. UnitTestsAfterDatabaseSetup tries to recreate a table that wasn't removed in the teardown. I don't think this is related to the tests failing or not.

Change 820184 had a related patch set uploaded (by Gergő Tisza; author: Gergő Tisza):

[mediawiki/extensions/CentralAuth@master] Add global_user_autocreate_serial to CentralUser table list

https://gerrit.wikimedia.org/r/820184

Change 820184 merged by jenkins-bot:

[mediawiki/extensions/CentralAuth@master] Add global_user_autocreate_serial to CentralUser table list

https://gerrit.wikimedia.org/r/820184

This did the trick.