Page MenuHomePhabricator

BlockTest should not fail under database constraints
Closed, ResolvedPublic

Description

After applying I326bb4a189bf881299b9fb678033a927b916efac (a crude but working way to work around bug 37702 and have database constraints on the database during unit testing), BlockTest fails twice:

  1. BlockTest::testBlockedUserCanNotCreateAccount

DBQueryError: A database error has occurred. Did you forget to run maintenance/update.php afte
r upgrading? See: https://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script
Query: COMMIT
Function: DatabaseBase::commit
Error: 23503 ERROR: insert or update on table "unittest_ipblocks" violates foreign key constr
aint "ut_ipblocks_ipb_user_fkey"
DETAIL: Key (ipb_user)=(14146) is not present in table "unittest_mwuser".

/usr/home/saper/test/mytest/includes/db/Database.php:1111
/usr/home/saper/test/mytest/includes/db/DatabasePostgres.php:511
/usr/home/saper/test/mytest/includes/db/Database.php:1077
/usr/home/saper/test/mytest/includes/db/Database.php:3477
/usr/home/saper/test/mytest/includes/db/Database.php:3462
/usr/home/saper/test/mytest/includes/db/DatabasePostgres.php:241
/usr/home/saper/test/mytest/includes/db/DatabasePostgres.php:884
/usr/home/saper/test/mytest/includes/Block.php:475
/usr/home/saper/test/mytest/tests/phpunit/includes/BlockTest.php:177
/usr/home/saper/test/mytest/tests/phpunit/MediaWikiTestCase.php:123
/usr/home/saper/test/mytest/tests/phpunit/MediaWikiPHPUnitCommand.php:80
/usr/home/saper/test/mytest/tests/phpunit/MediaWikiPHPUnitCommand.php:64
/usr/home/saper/test/mytest/tests/phpunit/phpunit.php:115

  1. BlockTest::testCrappyCrossWikiBlocks

DBQueryError: A database error has occurred. Did you forget to run maintenance/update.php after upgrading? See: https://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script
Query: COMMIT
Function: DatabaseBase::commit
Error: 23503 ERROR: insert or update on table "unittest_ipblocks" violates foreign key constraint "ut_ipblocks_ipb_user_fkey"
DETAIL: Key (ipb_user)=(14146) is not present in table "unittest_mwuser".

/usr/home/saper/test/mytest/includes/db/Database.php:1111
/usr/home/saper/test/mytest/includes/db/DatabasePostgres.php:511
/usr/home/saper/test/mytest/includes/db/Database.php:1077
/usr/home/saper/test/mytest/includes/db/Database.php:3477
/usr/home/saper/test/mytest/includes/db/Database.php:3462
/usr/home/saper/test/mytest/includes/db/DatabasePostgres.php:241
/usr/home/saper/test/mytest/includes/db/DatabasePostgres.php:884
/usr/home/saper/test/mytest/includes/Block.php:475
/usr/home/saper/test/mytest/tests/phpunit/includes/BlockTest.php:229
/usr/home/saper/test/mytest/tests/phpunit/MediaWikiTestCase./usr/home/saper/test/mytest/tests/phpunit/MediaWikiPHPUnitCommand.php:80
/usr/home/saper/test/mytest/tests/phpunit/MediaWikiPHPUnitCommand.php:64
/usr/home/saper/test/mytest/tests/phpunit/phpunit.php:115
php:123

Looks like the user ID 14146 is not fully in the database when the transaction is committed (we are using DEFERRED contraints so they are checked at commit, not immediately).

I have tried some simple ways to work around this and managed only fix
BlockTest::testCrappyCrossWikiBlocks by reordering calls.


Version: 1.23.0
Severity: normal

Details

Reference
bz58191

Event Timeline

bzimport raised the priority of this task from to High.Nov 22 2014, 2:32 AM
bzimport set Reference to bz58191.
bzimport added a subscriber: Unknown Object (MLST).
saper created this task.Dec 8 2013, 10:17 PM

Change 100334 had a related patch set uploaded by saper:
Let BlockTest.php respect database constraints

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

saper added a comment.Dec 8 2013, 10:22 PM

The above quick&dirty patch manages to "fix" BlockTest::testCrappyCrossWikiBlocks
but BlockTest::testBlockedUserCanNotCreateAccount still fails with:

  1. BlockTest::testBlockedUserCanNotCreateAccount

DBQueryError: A database error has occurred. Did you forget to run maintenance/update.php after upgrading? See: https://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script
Query: COMMIT
Function: DatabaseBase::commit
Error: 23503 ERROR: insert or update on table "unittest_ipblocks" violates foreign key constraint "ut_ipblocks_ipb_user_fkey"
DETAIL: Key (ipb_user)=(14146) is not present in table "unittest_mwuser".

/usr/home/saper/test/mytest/includes/db/Database.php:1111
/usr/home/saper/test/mytest/includes/db/DatabasePostgres.php:511
/usr/home/saper/test/mytest/includes/db/Database.php:1077
/usr/home/saper/test/mytest/includes/db/Database.php:3477
/usr/home/saper/test/mytest/includes/db/Database.php:3462
/usr/home/saper/test/mytest/includes/db/DatabasePostgres.php:241
/usr/home/saper/test/mytest/includes/db/DatabasePostgres.php:884
/usr/home/saper/test/mytest/includes/Block.php:475
/usr/home/saper/test/mytest/tests/phpunit/includes/BlockTest.php:178
/usr/home/saper/test/mytest/tests/phpunit/MediaWikiTestCase.php:123
/usr/home/saper/test/mytest/tests/phpunit/MediaWikiPHPUnitCommand.php:80
/usr/home/saper/test/mytest/tests/phpunit/MediaWikiPHPUnitCommand.php:64
/usr/home/saper/test/mytest/tests/phpunit/phpunit.php:115

Change 100334 merged by jenkins-bot:
Let BlockTest.php respect database constraints

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