From d15845b5dd0ff8d0a25308a87da9e21a404cb30a Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Sun, 1 Dec 2019 21:39:44 +0545 Subject: [PATCH] Fix try catch in tests/lib/Lock/LockingProvider.php --- tests/lib/Lock/LockingProvider.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/tests/lib/Lock/LockingProvider.php b/tests/lib/Lock/LockingProvider.php index 63a5c1a6c815..60283810ed34 100644 --- a/tests/lib/Lock/LockingProvider.php +++ b/tests/lib/Lock/LockingProvider.php @@ -91,16 +91,17 @@ public function testReleaseExclusiveLock() { $this->instance->acquireLock('foo', ILockingProvider::LOCK_EXCLUSIVE); } - /** - */ - public function testExclusiveLockAfterShared() { - $this->expectException(\OCP\Lock\LockedException::class); - + private function tryToAcquireExclusiveLockAfterShared() { $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); $this->assertTrue($this->instance->isLocked('foo', ILockingProvider::LOCK_SHARED)); $this->instance->acquireLock('foo', ILockingProvider::LOCK_EXCLUSIVE); } + public function testExclusiveLockAfterShared() { + $this->expectException(\OCP\Lock\LockedException::class); + $this->tryToAcquireExclusiveLockAfterShared(); + } + public function testExclusiveLockAfterSharedReleased() { $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); $this->assertTrue($this->instance->isLocked('foo', ILockingProvider::LOCK_SHARED)); @@ -165,19 +166,22 @@ public function testReleaseAfterReleaseAll() { $this->instance->releaseLock('foo', ILockingProvider::LOCK_SHARED); } + private function tryToAcquireSharedLockAfterExclusive() { + $this->instance->acquireLock('foo', ILockingProvider::LOCK_EXCLUSIVE); + $this->assertTrue($this->instance->isLocked('foo', ILockingProvider::LOCK_EXCLUSIVE)); + $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); + } + /** */ public function testSharedLockAfterExclusive() { $this->expectException(\OCP\Lock\LockedException::class); - - $this->instance->acquireLock('foo', ILockingProvider::LOCK_EXCLUSIVE); - $this->assertTrue($this->instance->isLocked('foo', ILockingProvider::LOCK_EXCLUSIVE)); - $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); + $this->tryToAcquireSharedLockAfterExclusive(); } public function testLockedExceptionHasPathForShared() { try { - $this->testSharedLockAfterExclusive(); + $this->tryToAcquireSharedLockAfterExclusive(); $this->fail('Expected locked exception'); } catch (LockedException $e) { $this->assertEquals('foo', $e->getPath()); @@ -186,7 +190,7 @@ public function testLockedExceptionHasPathForShared() { public function testLockedExceptionHasPathForExclusive() { try { - $this->testExclusiveLockAfterShared(); + $this->tryToAcquireExclusiveLockAfterShared(); $this->fail('Expected locked exception'); } catch (LockedException $e) { $this->assertEquals('foo', $e->getPath());