Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2020-09-22 16:03:17 +0300
committerRobin Appelman <robin@icewind.nl>2020-10-20 18:48:25 +0300
commitd52328660eadac6fcd2183ee523c51e49f656914 (patch)
tree47bc3e5ef4161248a081682f892c1876d17b65f3 /apps/files/tests
parent8676882bcba0fa149dc8cd5fa87dbcd95eb67264 (diff)
only run the background scanner for users that have unscanned files
instead of looping trough all users and seeing if they have unscanned files, we do a single query to find all storages that need scanning and run trough the users for them Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files/tests')
-rw-r--r--apps/files/tests/BackgroundJob/ScanFilesTest.php155
1 files changed, 60 insertions, 95 deletions
diff --git a/apps/files/tests/BackgroundJob/ScanFilesTest.php b/apps/files/tests/BackgroundJob/ScanFilesTest.php
index 75557955d6a..1bc449c6c62 100644
--- a/apps/files/tests/BackgroundJob/ScanFilesTest.php
+++ b/apps/files/tests/BackgroundJob/ScanFilesTest.php
@@ -25,129 +25,94 @@
namespace OCA\Files\Tests\BackgroundJob;
+use OC\Files\Mount\MountPoint;
+use OC\Files\Storage\Temporary;
use OCA\Files\BackgroundJob\ScanFiles;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
+use OCP\ILogger;
use OCP\IUser;
use OCP\IUserManager;
use Test\TestCase;
+use Test\Traits\MountProviderTrait;
+use Test\Traits\UserTrait;
/**
* Class ScanFilesTest
*
* @package OCA\Files\Tests\BackgroundJob
+ * @group DB
*/
class ScanFilesTest extends TestCase {
- /** @var IConfig */
- private $config;
- /** @var IUserManager */
- private $userManager;
+ use UserTrait;
+ use MountProviderTrait;
+
/** @var ScanFiles */
private $scanFiles;
+ /** @var \OCP\Files\Config\IUserMountCache */
+ private $mountCache;
protected function setUp(): void {
parent::setUp();
- $this->config = $this->createMock(IConfig::class);
- $this->userManager = $this->createMock(IUserManager::class);
+ $config = $this->createMock(IConfig::class);
+ $userManager = $this->createMock(IUserManager::class);
+ $dispatcher = $this->createMock(IEventDispatcher::class);
+ $logger = $this->createMock(ILogger::class);
+ $connection = \OC::$server->getDatabaseConnection();
+ $this->mountCache = \OC::$server->getUserMountCache();
$this->scanFiles = $this->getMockBuilder('\OCA\Files\BackgroundJob\ScanFiles')
- ->setConstructorArgs([
- $this->config,
- $this->userManager,
- ])
- ->setMethods(['runScanner'])
- ->getMock();
+ ->setConstructorArgs([
+ $config,
+ $userManager,
+ $dispatcher,
+ $logger,
+ $connection,
+ ])
+ ->setMethods(['runScanner'])
+ ->getMock();
}
- public function testRunWithoutUsers() {
- $this->config
- ->expects($this->at(0))
- ->method('getSystemValueBool')
- ->with('files_no_background_scan', false)
- ->willReturn(false);
- $this->config
- ->expects($this->at(1))
- ->method('getAppValue')
- ->with('files', 'cronjob_scan_files', 0)
- ->willReturn(50);
- $this->userManager
- ->expects($this->at(0))
- ->method('search')
- ->with('', 500, 50)
- ->willReturn([]);
- $this->userManager
- ->expects($this->at(1))
- ->method('search')
- ->with('', 500)
- ->willReturn([]);
- $this->config
- ->expects($this->at(2))
- ->method('setAppValue')
- ->with('files', 'cronjob_scan_files', 500);
-
+ private function runJob() {
$this->invokePrivate($this->scanFiles, 'run', [[]]);
}
- public function testRunWithUsers() {
- $fakeUser = $this->createMock(IUser::class);
- $this->config
- ->expects($this->at(0))
- ->method('getSystemValueBool')
- ->with('files_no_background_scan', false)
- ->willReturn(false);
- $this->config
- ->expects($this->at(1))
- ->method('getAppValue')
- ->with('files', 'cronjob_scan_files', 0)
- ->willReturn(50);
- $this->userManager
- ->expects($this->at(0))
- ->method('search')
- ->with('', 500, 50)
- ->willReturn([
- $fakeUser
- ]);
- $this->config
- ->expects($this->at(2))
- ->method('setAppValue')
- ->with('files', 'cronjob_scan_files', 550);
- $this->scanFiles
- ->expects($this->once())
- ->method('runScanner')
- ->with($fakeUser);
+ private function getUser(string $userId): IUser {
+ $user = $this->createMock(IUser::class);
+ $user->method('getUID')
+ ->willReturn($userId);
+ return $user;
+ }
- $this->invokePrivate($this->scanFiles, 'run', [[]]);
+ private function setupStorage(string $user, string $mountPoint) {
+ $storage = new Temporary([]);
+ $storage->mkdir('foo');
+ $storage->getScanner()->scan('');
+
+ $this->createUser($user, '');
+ $this->mountCache->registerMounts($this->getUser($user), [
+ new MountPoint($storage, $mountPoint)
+ ]);
+
+ return $storage;
}
- public function testRunWithUsersAndOffsetAtEndOfUserList() {
- $this->config
- ->expects($this->at(0))
- ->method('getSystemValueBool')
- ->with('files_no_background_scan', false)
- ->willReturn(false);
- $this->config
- ->expects($this->at(1))
- ->method('getAppValue')
- ->with('files', 'cronjob_scan_files', 0)
- ->willReturn(50);
- $this->userManager
- ->expects($this->at(0))
- ->method('search')
- ->with('', 500, 50)
- ->willReturn([]);
- $this->userManager
- ->expects($this->at(1))
- ->method('search')
- ->with('', 500)
- ->willReturn([]);
- $this->config
- ->expects($this->at(2))
- ->method('setAppValue')
- ->with('files', 'cronjob_scan_files', 500);
- $this->scanFiles
- ->expects($this->never())
- ->method('runScanner');
+ public function testAllScanned() {
+ $this->setupStorage('foouser', '/foousers/files/foo');
- $this->invokePrivate($this->scanFiles, 'run', [[]]);
+ $this->scanFiles->expects($this->never())
+ ->method('runScanner');
+ $this->runJob();
+ }
+
+ public function testUnscanned() {
+ $storage = $this->setupStorage('foouser', '/foousers/files/foo');
+ $storage->getCache()->put('foo', ['size' => -1]);
+
+ $this->scanFiles->expects($this->once())
+ ->method('runScanner')
+ ->with('foouser');
+ $this->runJob();
}
}