0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-04-29 03:20:29 +00:00
nextcloud_server/tests/lib/BackgroundJob/TimedJobTest.php
Christoph Wurst 2395526e6c
perf(cron): Delay (re)checking timed jobs
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
2025-03-31 13:21:29 +02:00

55 lines
1.3 KiB
PHP

<?php
/**
* SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\BackgroundJob;
use OCP\AppFramework\Utility\ITimeFactory;
class TimedJobTest extends \Test\TestCase {
private DummyJobList $jobList;
private ITimeFactory $time;
protected function setUp(): void {
parent::setUp();
$this->jobList = new DummyJobList();
$this->time = \OCP\Server::get(ITimeFactory::class);
}
public function testShouldRunAfterIntervalNew(): void {
$job = new TestTimedJobNew($this->time);
$job->setId(42);
$this->jobList->add($job);
$job->setLastRun(time() - 12);
$job->start($this->jobList);
$this->assertTrue($job->ran);
}
public function testShouldNotRunWithinIntervalNew(): void {
$job = new TestTimedJobNew($this->time);
$job->setId(42);
$this->jobList->add($job);
$job->setLastRun(time() - 5);
$job->start($this->jobList);
$this->assertFalse($job->ran);
}
public function testShouldNotTwiceNew(): void {
$job = new TestTimedJobNew($this->time);
$job->setId(42);
$this->jobList->add($job);
$job->setLastRun(time() - 15);
$job->start($this->jobList);
$this->assertTrue($job->ran);
$job->ran = false;
$job->start($this->jobList);
$this->assertFalse($job->ran);
}
}