Skip to content

Commit

Permalink
Fix try catch in tests/lib/Lock/LockingProvider.php
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-davis committed Dec 2, 2019
1 parent 184fc1a commit 2c31e90
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions tests/lib/Lock/LockingProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down

0 comments on commit 2c31e90

Please sign in to comment.