https://bugzilla.wikimedia.org/show_bug.cgi?id=58189

       Web browser: ---
            Bug ID: 58189
           Summary: LinksUpdateTest should respect database constrains
           Product: MediaWiki
           Version: 1.23-git
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: Unprioritized
         Component: Unit tests
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected],
                    [email protected]
            Blocks: 37702
    Classification: Unclassified
   Mobile Platform: ---

After enabling foreign key constraints on the database (see
I326bb4a189bf881299b9fb678033a927b916efac) LinksTestUpdate gives 7 errors.

This is because wikipage content is created in memory only, why LinksUpdate
attempts to operate on the database as well.

PostgreSQL in the current setup uses DEFERRED constraints, that means that all
references are checked at commit time, allowing various operations in the
meantime not immediately conforming to the constraints.

Sometimes fixings this kind of problem is trivial (see example at
I653a8bccdaa748a9bea453cd1dbf609a30e1ff6f), but LinksUpdateTest makes it more 
difficult because it attempts to use begin() and commit() in the middle
of the test.

7 errors:

1) LinksUpdateTest::testUpdate_pagelinks
DBQueryError: A database error has occurred. Did you forget to run
maintenance/update.php after upgrad
ing?  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_pagelinks" violates
foreign key constraint "u
t_pagelinks_pl_from_fkey"
DETAIL:  Key (pl_from)=(111) is not present in table "unittest_page".

/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/deferred/LinksUpdate.php:334
/usr/home/saper/test/mytest/includes/deferred/LinksUpdate.php:162
/usr/home/saper/test/mytest/includes/deferred/LinksUpdate.php:151
/usr/home/saper/test/mytest/tests/phpunit/includes/LinksUpdateTest.php:193
/usr/home/saper/test/mytest/tests/phpunit/includes/LinksUpdateTest.php:68
/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

2) LinksUpdateTest::testUpdate_externallinks
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_externallinks"
violates foreign key constraint "ut_externallinks_el_from_fkey"
DETAIL:  Key (el_from)=(111) is not present in table "unittest_page".

(...)
/usr/home/saper/test/mytest/includes/deferred/LinksUpdate.php:334
/usr/home/saper/test/mytest/includes/deferred/LinksUpdate.php:178
/usr/home/saper/test/mytest/includes/deferred/LinksUpdate.php:151
/usr/home/saper/test/mytest/tests/phpunit/includes/LinksUpdateTest.php:193
/usr/home/saper/test/mytest/tests/phpunit/includes/LinksUpdateTest.php:102
(...)

3) LinksUpdateTest::testUpdate_categorylinks
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_categorylinks"
violates foreign key constraint "ut_categorylinks_cl_from_fkey"
DETAIL:  Key (cl_from)=(111) is not present in table "unittest_page".

(...)
/usr/home/saper/test/mytest/includes/deferred/LinksUpdate.php:334
/usr/home/saper/test/mytest/includes/deferred/LinksUpdate.php:201
/usr/home/saper/test/mytest/includes/deferred/LinksUpdate.php:151
/usr/home/saper/test/mytest/tests/phpunit/includes/LinksUpdateTest.php:193
/usr/home/saper/test/mytest/tests/phpunit/includes/LinksUpdateTest.php:117
(...)

4) LinksUpdateTest::testUpdate_templatelinks
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_templatelinks"
violates foreign key constraint "ut_templatelinks_tl_from_fkey"
DETAIL:  Key (tl_from)=(111) is not present in table "unittest_page".



/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/deferred/LinksUpdate.php:334
/usr/home/saper/test/mytest/includes/deferred/LinksUpdate.php:193
/usr/home/saper/test/mytest/includes/deferred/LinksUpdate.php:151
/usr/home/saper/test/mytest/tests/phpunit/includes/LinksUpdateTest.php:193
/usr/home/saper/test/mytest/tests/phpunit/includes/LinksUpdateTest.php:144



5) LinksUpdateTest::testUpdate_imagelinks
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_imagelinks" violates
foreign key constraint "ut_imagelinks_il_from_fkey"
DETAIL:  Key (il_from)=(111) is not present in table "unittest_page".



/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/deferred/LinksUpdate.php:334
/usr/home/saper/test/mytest/includes/deferred/LinksUpdate.php:169
/usr/home/saper/test/mytest/includes/deferred/LinksUpdate.php:151
/usr/home/saper/test/mytest/tests/phpunit/includes/LinksUpdateTest.php:193
/usr/home/saper/test/mytest/tests/phpunit/includes/LinksUpdateTest.php:157
/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



6) LinksUpdateTest::testUpdate_langlinks
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_langlinks" violates 
foreign key constraint "ut_langlinks_ll_from_fkey"
DETAIL:  Key (ll_from)=(111) is not present in table "unittest_page".



/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/deferred/LinksUpdate.php:334
/usr/home/saper/test/mytest/includes/deferred/LinksUpdate.php:183
/usr/home/saper/test/mytest/includes/deferred/LinksUpdate.php:151
/usr/home/saper/test/mytest/tests/phpunit/includes/LinksUpdateTest.php:193
/usr/home/saper/test/mytest/tests/phpunit/includes/LinksUpdateTest.php:170
/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



7) LinksUpdateTest::testUpdate_page_props
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_page_props" violates
foreign key constraint "ut_page_props_pp_page_fkey"
DETAIL:  Key (pp_page)=(111) is not present in table "unittest_page".

/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/deferred/LinksUpdate.php:334
/usr/home/saper/test/mytest/includes/deferred/LinksUpdate.php:215
/usr/home/saper/test/mytest/includes/deferred/LinksUpdate.php:151
/usr/home/saper/test/mytest/tests/phpunit/includes/LinksUpdateTest.php:193
/usr/home/saper/test/mytest/tests/phpunit/includes/LinksUpdateTest.php:183
/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


Question #1: are LinksUpdates needed at all on the DB engine using triggers (ON
DELETE CASCADE) to remove dependent rows? If yes, what can we do to make it
create consistent contents of the database during this test?

Simplistic changes like


diff --git a/tests/phpunit/includes/LinksUpdateTest.php
b/tests/phpunit/includes/LinksUpdateTest.php
index b37ff2e..60ad76e 100644
--- a/tests/phpunit/includes/LinksUpdateTest.php
+++ b/tests/phpunit/includes/LinksUpdateTest.php
@@ -49,6 +49,10 @@ class LinksUpdateTest extends MediaWikiTestCase {
         $po = new ParserOutput();
         $po->setTitleText( $t->getPrefixedText() );

+        $pg = WikiPage::factory( $t );
+        $dbw = wfGetDB ( DB_MASTER );
+        $pg->insertOn( $dbw );
+
         return array( $t, $po );
     }

don't fix the problem and make even more tests to fail, like on MySQL:

1) LinksUpdateTest::testUpdate_pagelinks
row #1 missing
Failed asserting that a boolean is not empty.

/usr/home/saper/test/mytest/tests/phpunit/MediaWikiTestCase.php:678
/usr/home/saper/test/mytest/tests/phpunit/includes/LinksUpdateTest.php:200
/usr/home/saper/test/mytest/tests/phpunit/includes/LinksUpdateTest.php:72
/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

-- 
You are receiving this mail because:
You are the assignee for the bug.
You are on the CC list for the bug.
_______________________________________________
Wikibugs-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikibugs-l

Reply via email to