From 98dc0349b25714b75dc631b1e63724e926bae7d2 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 5 Mar 2013 11:03:20 -0800 Subject: [PATCH] [LockManager] Added ScopedLock::release function. * Added more lock unit tests. Change-Id: Ic359307cf26cfb621ae8d2db867801735a375dde --- includes/filebackend/lockmanager/ScopedLock.php | 13 +++++++++++++ .../includes/filebackend/FileBackendTest.php | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/includes/filebackend/lockmanager/ScopedLock.php b/includes/filebackend/lockmanager/ScopedLock.php index 5a80bee8b3..790a5c64a7 100644 --- a/includes/filebackend/lockmanager/ScopedLock.php +++ b/includes/filebackend/lockmanager/ScopedLock.php @@ -78,6 +78,19 @@ class ScopedLock { return null; } + /** + * Release a scoped lock and set any errors in the attatched Status object. + * This is useful for early release of locks before function scope is destroyed. + * This is the same as setting the lock object to null. + * + * @param ScopedLock $lock + * @return void + * @since 1.21 + */ + public static function release( ScopedLock &$lock = null ) { + $lock = null; + } + function __destruct() { $wasOk = $this->status->isOK(); $this->status->merge( $this->manager->unlock( $this->paths, $this->type ) ); diff --git a/tests/phpunit/includes/filebackend/FileBackendTest.php b/tests/phpunit/includes/filebackend/FileBackendTest.php index dac5edb341..a08910a92a 100644 --- a/tests/phpunit/includes/filebackend/FileBackendTest.php +++ b/tests/phpunit/includes/filebackend/FileBackendTest.php @@ -2072,6 +2072,23 @@ class FileBackendTest extends MediaWikiTestCase { $this->assertEquals( true, $status->isOK(), "Locking of files succeeded with OK status ($backendName)." ); } + + $status = Status::newGood(); + $sl = $this->backend->getScopedFileLocks( $paths, LockManager::LOCK_EX, $status ); + $this->assertType( 'ScopedLock', $sl, + "Scoped locking of files succeeded ($backendName)." ); + $this->assertEquals( array(), $status->errors, + "Scoped locking of files succeeded ($backendName)." ); + $this->assertEquals( true, $status->isOK(), + "Scoped locking of files succeeded with OK status ($backendName)." ); + + ScopedLock::release( $sl ); + $this->assertEquals( null, $sl, + "Scoped unlocking of files succeeded ($backendName)." ); + $this->assertEquals( array(), $status->errors, + "Scoped unlocking of files succeeded ($backendName)." ); + $this->assertEquals( true, $status->isOK(), + "Scoped unlocking of files succeeded with OK status ($backendName)." ); } // test helper wrapper for backend prepare() function -- 2.20.1