blob: 6375d9f6e7fa24dfad1f9c440c20bfb4f9bf3fbb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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());
}
}
|