Skip to content

Commit

Permalink
fix(tests): Pause trashbin for lock tests in ViewTest using rmdir and…
Browse files Browse the repository at this point in the history
… unlink

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Sep 24, 2024
1 parent af0b8fb commit 4adf5fd
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tests/lib/Files/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use OC\Files\Storage\Temporary;
use OC\Files\View;
use OC\Share20\ShareDisableChecker;
use OCA\Files_Trashbin\Trash\ITrashManager;
use OCP\Cache\CappedMemoryCache;
use OCP\Constants;
use OCP\Files\Config\IMountProvider;
Expand All @@ -26,9 +27,11 @@
use OCP\IDBConnection;
use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
use OCP\Server;
use OCP\Share\IManager as IShareManager;
use OCP\Share\IShare;
use OCP\Util;
use PHPUnit\Framework\MockObject\MockObject;
use Test\HookHelper;
use Test\TestMoveableMountPoint;
use Test\Traits\UserTrait;
Expand Down Expand Up @@ -1858,11 +1861,14 @@ public function testLockBasicOperation(
): void {
$view = new View('/' . $this->user . '/files/');

/** @var Temporary|\PHPUnit\Framework\MockObject\MockObject $storage */
/** @var Temporary&MockObject $storage */
$storage = $this->getMockBuilder(Temporary::class)
->setMethods([$operation])
->getMock();

/* Pause trash to avoid the trashbin intercepting rmdir and unlink calls */
Server::get(ITrashManager::class)->pauseTrash();

Filesystem::mount($storage, [], $this->user . '/');

// work directly on disk because mkdir might be mocked
Expand Down Expand Up @@ -1898,6 +1904,9 @@ function () use ($view, $lockedPath, &$lockTypeDuring, $returnValue) {
}

$this->assertEquals($expectedStrayLock, $this->getFileLockType($view, $lockedPath));

/* Resume trash to avoid side effects */
Server::get(ITrashManager::class)->resumeTrash();
}

/**
Expand Down Expand Up @@ -2007,6 +2016,9 @@ public function testLockBasicOperationUnlocksAfterException(
->setMethods([$operation])
->getMock();

/* Pause trash to avoid the trashbin intercepting rmdir and unlink calls */
Server::get(ITrashManager::class)->pauseTrash();

Filesystem::mount($storage, [], $this->user . '/');

// work directly on disk because mkdir might be mocked
Expand All @@ -2033,6 +2045,9 @@ function () {
}
$this->assertTrue($thrown, 'Exception was rethrown');
$this->assertNull($this->getFileLockType($view, $path), 'File got unlocked after exception');

/* Resume trash to avoid side effects */
Server::get(ITrashManager::class)->resumeTrash();
}

public function testLockBasicOperationUnlocksAfterLockException(): void {
Expand Down

0 comments on commit 4adf5fd

Please sign in to comment.