Page MenuHomePhabricator

Exception when running phpunit tests on vagrant
Closed, ResolvedPublic

Description

When I run unit tests on vagrant, I get this error:

[9541d85fcbb13499c016d90f] [no req] DBUnexpectedError from line 2629 of /vagrant/mediawiki/includes/libs/rdbms/database/Database.php: No atomic transaction is open (got Database::onTransactionPreCommitOrIdle).

This seems to be caused by duplicate key reporting: when running onTransactionPreCommitOrIdle, startAtomic calls getApproximateLagStatus which uses $this->srvCache. If $this->srvCache has reportDuplicate enabled, this causes transaction commit when executing doUpdate (which is executed synchronously because we're in CLI). This resets the mTrxLevel to 0 and this breaks endAtomic().

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptOct 8 2016, 12:02 AM

Change 314791 had a related patch set uploaded (by Smalyshev):
Disable reportDupes for unit tests

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

Reedy renamed this task from Exception when running uni tests on vagrant to Exception when running phpunit tests on vagrant.Oct 8 2016, 1:16 AM
aaron added a comment.Oct 8 2016, 6:26 AM

What doUpdate() method is being called? It's odd that logging would cause a commit. I seem to be missing something here.

It is called from trackDuplicateKeys, which calls DeferredUpdates::addCallableUpdate, which proceeds to execute update immediately via tryOpportunisticExecute.

Full backtrace up to the commit:

#1  Database->doCommit() called at [/vagrant/mediawiki/includes/libs/rdbms/database/Database.php:2769]
#2  Database->doCommit() called at [/vagrant/mediawiki/includes/libs/rdbms/database/Database.php:2749]
#3  Database->commit() called at [/vagrant/mediawiki/includes/libs/rdbms/database/Database.php:2832]
#4  Database->flushSnapshot() called at [/vagrant/mediawiki/includes/libs/rdbms/loadbalancer/LoadBalancer.php:1083]
#5  LoadBalancer->{closure}()
#6  call_user_func_array() called at [/vagrant/mediawiki/includes/libs/rdbms/loadbalancer/LoadBalancer.php:1381]
#7  LoadBalancer->forEachOpenMasterConnection() called at [/vagrant/mediawiki/includes/libs/rdbms/loadbalancer/LoadBalancer.php:1091]
#8  LoadBalancer->beginMasterChanges()
#9  call_user_func_array() called at [/vagrant/mediawiki/includes/libs/rdbms/lbfactory/LBFactory.php:177]
#10 LBFactory->{closure}()
#11 call_user_func_array() called at [/vagrant/mediawiki/includes/libs/rdbms/lbfactory/LBFactorySimple.php:145]
#12 LBFactorySimple->forEachLB() called at [/vagrant/mediawiki/includes/libs/rdbms/lbfactory/LBFactory.php:180]
#13 LBFactory->forEachLBCallMethod() called at [/vagrant/mediawiki/includes/libs/rdbms/lbfactory/LBFactory.php:201]
#14 LBFactory->beginMasterChanges() called at [/vagrant/mediawiki/includes/deferred/DeferredUpdates.php:246]
#15 DeferredUpdates::runUpdate() called at [/vagrant/mediawiki/includes/deferred/DeferredUpdates.php:209]
#16 DeferredUpdates::execute() called at [/vagrant/mediawiki/includes/deferred/DeferredUpdates.php:125]
#17 DeferredUpdates::doUpdates() called at [/vagrant/mediawiki/includes/deferred/DeferredUpdates.php:278]
#18 DeferredUpdates::tryOpportunisticExecute() called at [/vagrant/mediawiki/includes/deferred/DeferredUpdates.php:91]
#19 DeferredUpdates::addUpdate() called at [/vagrant/mediawiki/includes/deferred/DeferredUpdates.php:108]
#20 DeferredUpdates::addCallableUpdate()
#21 call_user_func() called at [/vagrant/mediawiki/includes/libs/objectcache/BagOStuff.php:215]
#22 BagOStuff->trackDuplicateKeys() called at [/vagrant/mediawiki/includes/libs/objectcache/BagOStuff.php:182]
#23 BagOStuff->get() called at [/vagrant/mediawiki/includes/libs/rdbms/database/DatabaseMysqlBase.php:770]
#24 DatabaseMysqlBase->getApproximateLagStatus() called at [/vagrant/mediawiki/includes/libs/rdbms/database/Database.php:2697]
#25 Database->begin() called at [/vagrant/mediawiki/includes/libs/rdbms/database/Database.php:2616]
#26 Database->startAtomic() called at [/vagrant/mediawiki/includes/libs/rdbms/database/Database.php:2472]
#27 Database->onTransactionPreCommitOrIdle() called at [/vagrant/mediawiki/includes/user/User.php:2367]
#28 User->clearSharedCache() called at [/vagrant/mediawiki/includes/user/User.php:2378]
#29 User->invalidateCache() called at [/vagrant/mediawiki/includes/user/User.php:3328]
#30 User->addGroup() called at [/vagrant/mediawiki/tests/phpunit/includes/TestUser.php:69]
#31 TestUser->__construct() called at [/vagrant/mediawiki/tests/phpunit/includes/TestUserRegistry.php:88]
#32 TestUserRegistry::getImmutableTestUser() called at [/vagrant/mediawiki/tests/phpunit/MediaWikiTestCase.php:138]
#33 MediaWikiTestCase::getTestUser() called at [/vagrant/mediawiki/tests/phpunit/MediaWikiTestCase.php:162]
#34 MediaWikiTestCase::getTestSysop() called at [/vagrant/mediawiki/tests/phpunit/MediaWikiTestCase.php:1021]
#35 MediaWikiTestCase->addCoreDBData() called at [/vagrant/mediawiki/tests/phpunit/MediaWikiTestCase.php:374]
#36 MediaWikiTestCase->run() called at [/vagrant/mediawiki/extensions/WikidataBuildResources/vendor/wikimedia/purtle/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747]
#37 PHPUnit_Framework_TestSuite->run() called at [/vagrant/mediawiki/extensions/WikidataBuildResources/vendor/wikimedia/purtle/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747]
#38 PHPUnit_Framework_TestSuite->run() called at [/vagrant/mediawiki/extensions/WikidataBuildResources/vendor/wikimedia/purtle/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:440]
#39 PHPUnit_TextUI_TestRunner->doRun() called at [/vagrant/mediawiki/extensions/WikidataBuildResources/vendor/wikimedia/purtle/vendor/phpunit/phpunit/src/TextUI/Command.php:149]
#40 PHPUnit_TextUI_Command->run() called at [/vagrant/mediawiki/extensions/WikidataBuildResources/vendor/wikimedia/purtle/vendor/phpunit/phpunit/src/TextUI/Command.php:100]
#41 PHPUnit_TextUI_Command::main() called at [/vagrant/mediawiki/tests/phpunit/phpunit.php:133]
#42 PHPUnitMaintClass->execute() called at [/vagrant/mediawiki/maintenance/doMaintenance.php:110]
#43 require(/vagrant/mediawiki/maintenance/doMaintenance.php) called at [/vagrant/mediawiki/tests/phpunit/phpunit.php:163]
aaron added a comment.Oct 8 2016, 10:52 PM

Looks like the +2 didn't make the change merge...trying again.

aaron added a comment.Oct 8 2016, 11:06 PM

DeferredUpdates::getBusyDbConnections() could also use some tightening too.

Change 314791 merged by jenkins-bot:
Disable reportDupes for unit tests

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

Change 315340 had a related patch set uploaded (by Aaron Schulz):
Guard Database::explicitTrxActive() against returning false while in begin()

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

Change 315340 merged by jenkins-bot:
Guard Database::explicitTrxActive() against returning false while in begin()

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

aaron closed this task as Resolved.Oct 12 2016, 4:31 PM
aaron claimed this task.