aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2025-02-12 09:54:07 +0100
committerChristoph Wurst <christoph@winzerhof-wurst.at>2025-03-31 13:21:29 +0200
commit2395526e6c25f1e8aafa1abf322a0d38c0ab5d54 (patch)
tree37f43af94d4078ba1579dfee6ed4a27b0604f60c /tests
parentd5ad9b86ef1deb35afb78e3f113798b18151d026 (diff)
downloadnextcloud-server-2395526e6c25f1e8aafa1abf322a0d38c0ab5d54.tar.gz
nextcloud-server-2395526e6c25f1e8aafa1abf322a0d38c0ab5d54.zip
perf(cron): Delay (re)checking timed jobsperf/cron/delay-timedjob-checking
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/BackgroundJob/JobListTest.php29
-rw-r--r--tests/lib/BackgroundJob/TestTimedJobNew.php26
-rw-r--r--tests/lib/BackgroundJob/TimedJobTest.php14
3 files changed, 52 insertions, 17 deletions
diff --git a/tests/lib/BackgroundJob/JobListTest.php b/tests/lib/BackgroundJob/JobListTest.php
index a9d7df0e6f4..bf21639d3aa 100644
--- a/tests/lib/BackgroundJob/JobListTest.php
+++ b/tests/lib/BackgroundJob/JobListTest.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -153,7 +156,11 @@ class JobListTest extends TestCase {
$this->assertFalse($this->instance->has($job, 10));
}
- protected function createTempJob($class, $argument, $reservedTime = 0, $lastChecked = 0) {
+ protected function createTempJob($class,
+ $argument,
+ int $reservedTime = 0,
+ int $lastChecked = 0,
+ int $lastRun = 0): int {
if ($lastChecked === 0) {
$lastChecked = time();
}
@@ -163,11 +170,12 @@ class JobListTest extends TestCase {
->values([
'class' => $query->createNamedParameter($class),
'argument' => $query->createNamedParameter($argument),
- 'last_run' => $query->createNamedParameter(0, IQueryBuilder::PARAM_INT),
+ 'last_run' => $query->createNamedParameter($lastRun, IQueryBuilder::PARAM_INT),
'last_checked' => $query->createNamedParameter($lastChecked, IQueryBuilder::PARAM_INT),
'reserved_at' => $query->createNamedParameter($reservedTime, IQueryBuilder::PARAM_INT),
]);
- $query->execute();
+ $query->executeStatement();
+ return $query->getLastInsertId();
}
public function testGetNext(): void {
@@ -200,6 +208,21 @@ class JobListTest extends TestCase {
$this->assertEquals(2, $nextJob->getArgument());
}
+ public function testGetNextSkipTimed(): void {
+ $job = new TestTimedJobNew($this->timeFactory);
+ $jobId = $this->createTempJob(get_class($job), 1, 123456789, 12345, 123456789 - 5);
+ $this->timeFactory->expects(self::atLeastOnce())
+ ->method('getTime')
+ ->willReturn(123456789);
+
+ $nextJob = $this->instance->getNext();
+
+ self::assertNull($nextJob);
+ $job = $this->instance->getById($jobId);
+ self::assertInstanceOf(TestTimedJobNew::class, $job);
+ self::assertEquals(123456789 - 5, $job->getLastRun());
+ }
+
public function testGetNextSkipNonExisting(): void {
$job = new TestJob();
$this->createTempJob('\OC\Non\Existing\Class', 1, 0, 12345);
diff --git a/tests/lib/BackgroundJob/TestTimedJobNew.php b/tests/lib/BackgroundJob/TestTimedJobNew.php
new file mode 100644
index 00000000000..a40c4033655
--- /dev/null
+++ b/tests/lib/BackgroundJob/TestTimedJobNew.php
@@ -0,0 +1,26 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+namespace Test\BackgroundJob;
+
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\BackgroundJob\TimedJob;
+
+class TestTimedJobNew extends TimedJob {
+ public bool $ran = false;
+
+ public function __construct(ITimeFactory $timeFactory) {
+ parent::__construct($timeFactory);
+ $this->setInterval(10);
+ }
+
+ public function run($argument) {
+ $this->ran = true;
+ }
+}
diff --git a/tests/lib/BackgroundJob/TimedJobTest.php b/tests/lib/BackgroundJob/TimedJobTest.php
index ad0f54ebe4a..6037365104f 100644
--- a/tests/lib/BackgroundJob/TimedJobTest.php
+++ b/tests/lib/BackgroundJob/TimedJobTest.php
@@ -8,20 +8,6 @@
namespace Test\BackgroundJob;
use OCP\AppFramework\Utility\ITimeFactory;
-use OCP\BackgroundJob\TimedJob;
-
-class TestTimedJobNew extends TimedJob {
- public bool $ran = false;
-
- public function __construct(ITimeFactory $timeFactory) {
- parent::__construct($timeFactory);
- $this->setInterval(10);
- }
-
- public function run($argument) {
- $this->ran = true;
- }
-}
class TimedJobTest extends \Test\TestCase {
private DummyJobList $jobList;