aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/cache/MessageCacheTest.php
diff options
context:
space:
mode:
authorAaron Schulz <aschulz@wikimedia.org>2016-10-27 22:53:51 -0700
committerKrinkle <krinklemail@gmail.com>2017-01-25 00:46:41 +0000
commitc962b480568ea13634a682c66f49c266148c3806 (patch)
tree3b24c546454fa2be54ea837052cf425e07fc8f11 /tests/phpunit/includes/cache/MessageCacheTest.php
parentdecb55fdf90e0cef65475a1062259a50a32f41a4 (diff)
downloadmediawikicore-c962b480568ea13634a682c66f49c266148c3806.tar.gz
mediawikicore-c962b480568ea13634a682c66f49c266148c3806.zip
Avoid races in MessageCache::replace()
Do the process cache update immediately (as before) but push the shared cache updates to a deferred update. This update will thus start with a clear transaction snapshot, so it can acquire the lock before the first SELECT as is proper. Also added some missing method visibilities. Bug: T144952 Change-Id: I462554b300d4688b09ab80cd1bb8a4340ffaa786
Diffstat (limited to 'tests/phpunit/includes/cache/MessageCacheTest.php')
-rw-r--r--tests/phpunit/includes/cache/MessageCacheTest.php31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/phpunit/includes/cache/MessageCacheTest.php b/tests/phpunit/includes/cache/MessageCacheTest.php
index bd744c01ca6d..a12c8b2d09ad 100644
--- a/tests/phpunit/includes/cache/MessageCacheTest.php
+++ b/tests/phpunit/includes/cache/MessageCacheTest.php
@@ -99,6 +99,37 @@ class MessageCacheTest extends MediaWikiLangTestCase {
];
}
+ public function testReplaceMsg() {
+ global $wgContLang;
+
+ $messageCache = MessageCache::singleton();
+ $message = 'go';
+ $uckey = $wgContLang->ucfirst( $message );
+ $oldText = $messageCache->get( $message ); // "Ausführen"
+
+ $dbw = wfGetDB( DB_MASTER );
+ $dbw->startAtomic( __METHOD__ ); // simulate request and block deferred updates
+ $messageCache->replace( $uckey, 'Allez!' );
+ $this->assertEquals( 'Allez!',
+ $messageCache->getMsgFromNamespace( $uckey, 'de' ),
+ 'Updates are reflected in-process immediately' );
+ $this->assertEquals( 'Allez!',
+ $messageCache->get( $message ),
+ 'Updates are reflected in-process immediately' );
+ $this->makePage( 'Go', 'de', 'Race!' );
+ $dbw->endAtomic( __METHOD__ );
+
+ $this->assertEquals( 0,
+ DeferredUpdates::pendingUpdatesCount(),
+ 'Post-commit deferred update triggers a run of all updates' );
+
+ $this->assertEquals( 'Race!', $messageCache->get( $message ), 'Correct final contents' );
+
+ $this->makePage( 'Go', 'de', $oldText );
+ $messageCache->replace( $uckey, $oldText ); // deferred update runs immediately
+ $this->assertEquals( $oldText, $messageCache->get( $message ), 'Content restored' );
+ }
+
/**
* There's a fallback case where the message key is given as fully qualified -- this
* should ignore the passed $lang and use the language from the key