diff options
author | Louis Chemineau <louis@chmn.me> | 2024-02-08 15:31:19 +0100 |
---|---|---|
committer | Louis Chemineau <louis@chmn.me> | 2024-02-08 15:31:19 +0100 |
commit | 898df41de968321926e10ad532a64c3915ddad29 (patch) | |
tree | 57a0e5ada151890ddf71550f22b502e1f67aeffd /tests | |
parent | d9d60238c7aaab9c61bf2d50c15aa59bc88c8975 (diff) | |
download | nextcloud-server-898df41de968321926e10ad532a64c3915ddad29.tar.gz nextcloud-server-898df41de968321926e10ad532a64c3915ddad29.zip |
Revert "Merge branch 'master' of github.com:nextcloud/server"
This reverts commit d9d60238c7aaab9c61bf2d50c15aa59bc88c8975, reversing
changes made to ba3fdb0cdcfbb84f0080a2146a4ba2f01569915d.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/BackgroundJob/DummyJobList.php | 2 | ||||
-rw-r--r-- | tests/lib/BackgroundJob/JobTest.php | 22 | ||||
-rw-r--r-- | tests/lib/BackgroundJob/QueuedJobTest.php | 34 | ||||
-rw-r--r-- | tests/lib/BackgroundJob/TestJob.php | 2 | ||||
-rw-r--r-- | tests/lib/BackgroundJob/TimedJobTest.php | 67 | ||||
-rw-r--r-- | tests/lib/Command/CronBusTest.php | 2 |
6 files changed, 100 insertions, 29 deletions
diff --git a/tests/lib/BackgroundJob/DummyJobList.php b/tests/lib/BackgroundJob/DummyJobList.php index 05a9e5928c2..7886e8f877c 100644 --- a/tests/lib/BackgroundJob/DummyJobList.php +++ b/tests/lib/BackgroundJob/DummyJobList.php @@ -116,7 +116,7 @@ class DummyJobList extends \OC\BackgroundJob\JobList { /** * set the job that was last ran * - * @param \OCP\BackgroundJob\Job $job + * @param \OC\BackgroundJob\Job $job */ public function setLastJob(IJob $job): void { $i = array_search($job, $this->jobs); diff --git a/tests/lib/BackgroundJob/JobTest.php b/tests/lib/BackgroundJob/JobTest.php index c3a4a7d0552..a4e0dcf4fd6 100644 --- a/tests/lib/BackgroundJob/JobTest.php +++ b/tests/lib/BackgroundJob/JobTest.php @@ -9,20 +9,16 @@ namespace Test\BackgroundJob; use OCP\AppFramework\Utility\ITimeFactory; -use Psr\Log\LoggerInterface; +use OCP\ILogger; class JobTest extends \Test\TestCase { private $run = false; private ITimeFactory $timeFactory; - private LoggerInterface $logger; protected function setUp(): void { parent::setUp(); $this->run = false; - $this->timeFactory = \OCP\Server::get(ITimeFactory::class); - $this->logger = $this->createMock(LoggerInterface::class); - - \OC::$server->registerService(LoggerInterface::class, fn ($c) => $this->logger); + $this->timeFactory = \OC::$server->get(ITimeFactory::class); } public function testRemoveAfterException() { @@ -33,11 +29,14 @@ class JobTest extends \Test\TestCase { }); $jobList->add($job); - $this->logger->expects($this->once()) + $logger = $this->getMockBuilder(ILogger::class) + ->disableOriginalConstructor() + ->getMock(); + $logger->expects($this->once()) ->method('error'); $this->assertCount(1, $jobList->getAll()); - $job->start($jobList); + $job->execute($jobList, $logger); $this->assertTrue($this->run); $this->assertCount(1, $jobList->getAll()); } @@ -50,11 +49,14 @@ class JobTest extends \Test\TestCase { }); $jobList->add($job); - $this->logger->expects($this->once()) + $logger = $this->getMockBuilder(ILogger::class) + ->disableOriginalConstructor() + ->getMock(); + $logger->expects($this->once()) ->method('error'); $this->assertCount(1, $jobList->getAll()); - $job->start($jobList); + $job->execute($jobList, $logger); $this->assertTrue($this->run); $this->assertCount(1, $jobList->getAll()); } diff --git a/tests/lib/BackgroundJob/QueuedJobTest.php b/tests/lib/BackgroundJob/QueuedJobTest.php index aaf24957f09..9378816ce61 100644 --- a/tests/lib/BackgroundJob/QueuedJobTest.php +++ b/tests/lib/BackgroundJob/QueuedJobTest.php @@ -9,10 +9,20 @@ namespace Test\BackgroundJob; use OCP\AppFramework\Utility\ITimeFactory; -use OCP\BackgroundJob\QueuedJob; -class TestQueuedJobNew extends QueuedJob { - public bool $ran = false; +class TestQueuedJob extends \OC\BackgroundJob\QueuedJob { + public $ran = false; + + + public function run($argument) { + $this->ran = true; + } +} + + +class TestQueuedJobNew extends \OCP\BackgroundJob\QueuedJob { + public $ran = false; + public function run($argument) { $this->ran = true; @@ -20,7 +30,10 @@ class TestQueuedJobNew extends QueuedJob { } class QueuedJobTest extends \Test\TestCase { - private DummyJobList $jobList; + /** + * @var DummyJobList $jobList + */ + private $jobList; protected function setUp(): void { parent::setUp(); @@ -28,13 +41,22 @@ class QueuedJobTest extends \Test\TestCase { $this->jobList = new DummyJobList(); } + public function testJobShouldBeRemoved() { + $job = new TestQueuedJob(); + $this->jobList->add($job); + + $this->assertTrue($this->jobList->has($job, null)); + $job->execute($this->jobList); + $this->assertTrue($job->ran); + } + public function testJobShouldBeRemovedNew() { - $job = new TestQueuedJobNew(\OCP\Server::get(ITimeFactory::class)); + $job = new TestQueuedJobNew(\OC::$server->query(ITimeFactory::class)); $job->setId(42); $this->jobList->add($job); $this->assertTrue($this->jobList->has($job, null)); - $job->start($this->jobList); + $job->execute($this->jobList); $this->assertTrue($job->ran); } } diff --git a/tests/lib/BackgroundJob/TestJob.php b/tests/lib/BackgroundJob/TestJob.php index 54b0ec7d9ea..cc7a4651c4b 100644 --- a/tests/lib/BackgroundJob/TestJob.php +++ b/tests/lib/BackgroundJob/TestJob.php @@ -23,7 +23,7 @@ class TestJob extends \OCP\BackgroundJob\Job { * @param callable $callback */ public function __construct(ITimeFactory $time = null, $testCase = null, $callback = null) { - parent::__construct($time ?? \OCP\Server::get(ITimeFactory::class)); + parent::__construct($time ?? \OC::$server->get(ITimeFactory::class)); $this->testCase = $testCase; $this->callback = $callback; } diff --git a/tests/lib/BackgroundJob/TimedJobTest.php b/tests/lib/BackgroundJob/TimedJobTest.php index d0dd794a77c..12f1c43adde 100644 --- a/tests/lib/BackgroundJob/TimedJobTest.php +++ b/tests/lib/BackgroundJob/TimedJobTest.php @@ -9,10 +9,23 @@ namespace Test\BackgroundJob; use OCP\AppFramework\Utility\ITimeFactory; -use OCP\BackgroundJob\TimedJob; -class TestTimedJobNew extends TimedJob { - public bool $ran = false; +class TestTimedJob extends \OC\BackgroundJob\TimedJob { + /** @var bool */ + public $ran = false; + + public function __construct() { + $this->setInterval(10); + } + + public function run($argument) { + $this->ran = true; + } +} + +class TestTimedJobNew extends \OCP\BackgroundJob\TimedJob { + /** @var bool */ + public $ran = false; public function __construct(ITimeFactory $timeFactory) { parent::__construct($timeFactory); @@ -25,23 +38,57 @@ class TestTimedJobNew extends TimedJob { } class TimedJobTest extends \Test\TestCase { - private DummyJobList $jobList; - private ITimeFactory $time; + /** @var DummyJobList $jobList */ + private $jobList; + + /** @var ITimeFactory */ + private $time; protected function setUp(): void { parent::setUp(); $this->jobList = new DummyJobList(); - $this->time = \OCP\Server::get(ITimeFactory::class); + $this->time = \OC::$server->query(ITimeFactory::class); + } + + public function testShouldRunAfterInterval() { + $job = new TestTimedJob(); + $this->jobList->add($job); + + $job->setLastRun(time() - 12); + $job->execute($this->jobList); + $this->assertTrue($job->ran); } + public function testShouldNotRunWithinInterval() { + $job = new TestTimedJob(); + $this->jobList->add($job); + + $job->setLastRun(time() - 5); + $job->execute($this->jobList); + $this->assertFalse($job->ran); + } + + public function testShouldNotTwice() { + $job = new TestTimedJob(); + $this->jobList->add($job); + + $job->setLastRun(time() - 15); + $job->execute($this->jobList); + $this->assertTrue($job->ran); + $job->ran = false; + $job->execute($this->jobList); + $this->assertFalse($job->ran); + } + + public function testShouldRunAfterIntervalNew() { $job = new TestTimedJobNew($this->time); $job->setId(42); $this->jobList->add($job); $job->setLastRun(time() - 12); - $job->start($this->jobList); + $job->execute($this->jobList); $this->assertTrue($job->ran); } @@ -51,7 +98,7 @@ class TimedJobTest extends \Test\TestCase { $this->jobList->add($job); $job->setLastRun(time() - 5); - $job->start($this->jobList); + $job->execute($this->jobList); $this->assertFalse($job->ran); } @@ -61,10 +108,10 @@ class TimedJobTest extends \Test\TestCase { $this->jobList->add($job); $job->setLastRun(time() - 15); - $job->start($this->jobList); + $job->execute($this->jobList); $this->assertTrue($job->ran); $job->ran = false; - $job->start($this->jobList); + $job->execute($this->jobList); $this->assertFalse($job->ran); } } diff --git a/tests/lib/Command/CronBusTest.php b/tests/lib/Command/CronBusTest.php index 4b3c7dca95a..ea610a135d8 100644 --- a/tests/lib/Command/CronBusTest.php +++ b/tests/lib/Command/CronBusTest.php @@ -44,7 +44,7 @@ class CronBusTest extends AsyncBusTest { protected function runJobs() { $jobs = $this->jobList->getAll(); foreach ($jobs as $job) { - $job->start($this->jobList); + $job->execute($this->jobList); } } } |