Page MenuHomePhabricator

Unit tests for MovePage throw "uncommitted DB writes" error in 1.27 but not in 1.26
Open, MediumPublic

Description

A unit test that worked fine in MediaWiki 1.26 throws an error in MediaWiki 1.27.

PHP Notice:  Uncommitted DB writes (transaction from DatabaseBase::query (LinkCache::addLinkObj)). in /home/wiki/wiki/wiki/includes/db/Database.php on line 3303
PHP Stack trace:
PHP   1. {main}() /home/wiki/wiki/wiki/tests/phpunit/phpunit.php:0
PHP   2. PHPUnit_TextUI_Command::main() /home/wiki/wiki/wiki/tests/phpunit/phpunit.php:262
PHP   3. PHPUnit_TextUI_Command->run() /home/wiki/wiki/wiki/vendor/phpunit/phpunit/src/TextUI/Command.php:100
PHP   4. DatabaseBase->__destruct() /home/wiki/wiki/wiki/includes/db/Database.php:0
PHP   5. trigger_error() /home/wiki/wiki/wiki/includes/db/Database.php:3303

Here is a minimal example, which performs two calls to MovePage::move. The second call causes the error.

<?php
/**                                                                                                                    
 * @group BadTest                                                                                                      
 * @group Database                                                                                                     
 * @group Destructive                                                                                                  
 */
class BadTest extends MediaWikiTestCase {

        protected function setUp() {
                parent::setUp();
                $this->tablesUsed[] = 'page';
        }

        public function testMoveBug() {
                $pageName = 'Foobar';
                $talkPageName = 'Talk:' . $pageName;
                $user = RequestContext::getMain()->getUser();

                foreach ( array($pageName, $talkPageName) as $name ) {
                        $page = WikiPage::factory( Title::newFromText($name) );
                        $page->doEditContent(
                                new WikitextContent( 'some content' ),
                                'my summary',
                                EDIT_NEW,
                                false,
                                $user
                        );
                }

                // Move a page                                                                                         
                $source = Title::newFromText($pageName);
                $dest = Title::newFromText('whatever');
                $mp = new MovePage($source, $dest);
                $mp->move($user, 'some reason', true);

                // Move a second page                                                                                  
                $sourceTalk = Title::newFromText($talkPageName);
                $destTalk = Title::newFromText('Talk:anything');
                $mp = new MovePage($sourceTalk, $destTalk);
                // If you comment out the next line, the error disappears                                              
                $mp->move($user, 'some reason', true);

                $this->assertTrue(true);
        }

}

To reproduce, use --group BadTest.

If you comment out the second call to $mp->move, the error disappears.

The error happens only during unit testing, not when the code is run normally on a MediaWiki site.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptAug 2 2016, 4:11 PM

I notice that the LinkCache class (the subject of the error message) was reimplemented in 1.27 to use HashBagOStuff instead of MapCacheLRU.

Legoktm updated the task description. (Show Details)Aug 3 2016, 6:27 AM
Legoktm added a subscriber: Legoktm.Aug 3 2016, 6:30 AM

Hmm...

(sid)km@km-tp:~/projects/vagrant/mediawiki/tests/phpunit$ php phpunit.php includes/MovePageBrokenTest.php 
Using PHP 7.0.9-1
PHPUnit 4.8.24 by Sebastian Bergmann and contributors.

..

Time: 841 ms, Memory: 22.00MB

OK (2 tests, 2 assertions)

database type? php version? OS? Just to rule out different factors...

Also, can you check the return value of MovePage::move()? $this->assertTrue( $status->isOK() ) or something.

maiden_taiwan added a comment.EditedAug 3 2016, 1:40 PM

Thank you so much for trying to reproduce the issue. With your results in hand, I think I have narrowed down the cause. Would you mind repeating your test, but with the TitleKey extension installed (the 1.27 branch version)? When I remove this extension, I can no longer reproduce the issue.

FYI, this is with PHP as follows:

PHP 7.0.8-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.8-0ubuntu0.16.04.1, Copyright (c) 1999-2016, by Zend Technologies
    with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans

and mySQL as follows:

mysql  Ver 14.14 Distrib 5.7.13, for Linux (x86_64) using  EditLine wrapper

on Ubuntu 16.04 LTS Xenial.

Also, all the MovePage calls succeed.

Krinkle triaged this task as Medium priority.Jan 12 2017, 8:34 PM
Krinkle added a project: Regression.
Krinkle moved this task from Inbox to PHPUnit on the MediaWiki-Core-Testing board.Jul 7 2017, 5:12 AM