aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/tests/SetupChecks/TaskProcessingPickupSpeedTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/settings/tests/SetupChecks/TaskProcessingPickupSpeedTest.php')
-rw-r--r--apps/settings/tests/SetupChecks/TaskProcessingPickupSpeedTest.php73
1 files changed, 73 insertions, 0 deletions
diff --git a/apps/settings/tests/SetupChecks/TaskProcessingPickupSpeedTest.php b/apps/settings/tests/SetupChecks/TaskProcessingPickupSpeedTest.php
new file mode 100644
index 00000000000..6375d9f6e7f
--- /dev/null
+++ b/apps/settings/tests/SetupChecks/TaskProcessingPickupSpeedTest.php
@@ -0,0 +1,73 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests;
+
+use OCA\Settings\SetupChecks\TaskProcessingPickupSpeed;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\IL10N;
+use OCP\SetupCheck\SetupResult;
+use OCP\TaskProcessing\IManager;
+use OCP\TaskProcessing\Task;
+use Test\TestCase;
+
+class TaskProcessingPickupSpeedTest extends TestCase {
+ private IL10N $l10n;
+ private ITimeFactory $timeFactory;
+ private IManager $taskProcessingManager;
+
+ private TaskProcessingPickupSpeed $check;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
+ $this->timeFactory = $this->getMockBuilder(ITimeFactory::class)->getMock();
+ $this->taskProcessingManager = $this->getMockBuilder(IManager::class)->getMock();
+
+ $this->check = new TaskProcessingPickupSpeed(
+ $this->l10n,
+ $this->taskProcessingManager,
+ $this->timeFactory,
+ );
+ }
+
+ public function testPass(): void {
+ $tasks = [];
+ for ($i = 0; $i < 100; $i++) {
+ $task = new Task('test', ['test' => 'test'], 'settings', 'user' . $i);
+ $task->setStartedAt(0);
+ if ($i < 15) {
+ $task->setScheduledAt(60 * 5); // 15% get 5mins
+ } else {
+ $task->setScheduledAt(60); // the rest gets 1min
+ }
+ $tasks[] = $task;
+ }
+ $this->taskProcessingManager->method('getTasks')->willReturn($tasks);
+
+ $this->assertEquals(SetupResult::SUCCESS, $this->check->run()->getSeverity());
+ }
+
+ public function testFail(): void {
+ $tasks = [];
+ for ($i = 0; $i < 100; $i++) {
+ $task = new Task('test', ['test' => 'test'], 'settings', 'user' . $i);
+ $task->setStartedAt(0);
+ if ($i < 30) {
+ $task->setScheduledAt(60 * 5); // 30% get 5mins
+ } else {
+ $task->setScheduledAt(60); // the rest gets 1min
+ }
+ $tasks[] = $task;
+ }
+ $this->taskProcessingManager->method('getTasks')->willReturn($tasks);
+
+ $this->assertEquals(SetupResult::WARNING, $this->check->run()->getSeverity());
+ }
+}