[LockManager] Added ScopedLock::release function.
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 5 Mar 2013 19:03:20 +0000 (11:03 -0800)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 5 Mar 2013 21:33:51 +0000 (13:33 -0800)
* Added more lock unit tests.

Change-Id: Ic359307cf26cfb621ae8d2db867801735a375dde

includes/filebackend/lockmanager/ScopedLock.php
tests/phpunit/includes/filebackend/FileBackendTest.php

index 5a80bee..790a5c6 100644 (file)
@@ -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 ) );
index dac5edb..a08910a 100644 (file)
@@ -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