Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChristoph Wurst <ChristophWurst@users.noreply.github.com>2018-10-19 08:40:35 +0300
committerGitHub <noreply@github.com>2018-10-19 08:40:35 +0300
commita1ea504edf529a364be9b66fda5d100d62dcc0b9 (patch)
treee3617226613c8cf17bd61ef0f710cf5ae25cec21 /tests
parent5daa4f27e1a4840a1a722729ca5ebafb6e749a43 (diff)
parent8493f49211290e3aea48cc9055a615b69725ac84 (diff)
Merge pull request #11711 from nextcloud/feature/backgroundjobs_ocp
Add proper backgroundjobs to OCP
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/BackgroundJob/QueuedJobTest.php52
-rw-r--r--tests/lib/BackgroundJob/TimedJobTest.php113
2 files changed, 108 insertions, 57 deletions
diff --git a/tests/lib/BackgroundJob/QueuedJobTest.php b/tests/lib/BackgroundJob/QueuedJobTest.php
index a3e9cc296a0..73b245f93a5 100644
--- a/tests/lib/BackgroundJob/QueuedJobTest.php
+++ b/tests/lib/BackgroundJob/QueuedJobTest.php
@@ -8,18 +8,24 @@
namespace Test\BackgroundJob;
+use OCP\AppFramework\Utility\ITimeFactory;
+
class TestQueuedJob extends \OC\BackgroundJob\QueuedJob {
- private $testCase;
+ public $ran = false;
- /**
- * @param QueuedJobTest $testCase
- */
- public function __construct($testCase) {
- $this->testCase = $testCase;
+
+ public function run($argument) {
+ $this->ran = true;
}
+}
+
+
+class TestQueuedJobNew extends \OCP\BackgroundJob\QueuedJob {
+ public $ran = false;
+
public function run($argument) {
- $this->testCase->markRun();
+ $this->ran = true;
}
}
@@ -28,29 +34,29 @@ class QueuedJobTest extends \Test\TestCase {
* @var DummyJobList $jobList
*/
private $jobList;
- /**
- * @var \OC\BackgroundJob\TimedJob $job
- */
- private $job;
-
- private $jobRun = false;
-
- public function markRun() {
- $this->jobRun = true;
- }
protected function setup() {
parent::setUp();
$this->jobList = new DummyJobList();
- $this->job = new TestQueuedJob($this);
- $this->jobList->add($this->job);
- $this->jobRun = false;
}
public function testJobShouldBeRemoved() {
- $this->assertTrue($this->jobList->has($this->job, null));
- $this->job->execute($this->jobList);
- $this->assertTrue($this->jobRun);
+ $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(\OC::$server->query(ITimeFactory::class));
+ $job->setId(42);
+ $this->jobList->add($job);
+
+ $this->assertTrue($this->jobList->has($job, null));
+ $job->execute($this->jobList);
+ $this->assertTrue($job->ran);
}
}
diff --git a/tests/lib/BackgroundJob/TimedJobTest.php b/tests/lib/BackgroundJob/TimedJobTest.php
index 5652a5c9901..e684ad8c1e6 100644
--- a/tests/lib/BackgroundJob/TimedJobTest.php
+++ b/tests/lib/BackgroundJob/TimedJobTest.php
@@ -8,65 +8,110 @@
namespace Test\BackgroundJob;
+use OCP\AppFramework\Utility\ITimeFactory;
+
class TestTimedJob extends \OC\BackgroundJob\TimedJob {
- private $testCase;
+ /** @var bool */
+ public $ran = false;
- /**
- * @param TimedJobTest $testCase
- */
- public function __construct($testCase) {
+ public function __construct() {
$this->setInterval(10);
- $this->testCase = $testCase;
}
public function run($argument) {
- $this->testCase->markRun();
+ $this->ran = true;
}
}
-class TimedJobTest extends \Test\TestCase {
- /**
- * @var DummyJobList $jobList
- */
- private $jobList;
- /**
- * @var \OC\BackgroundJob\TimedJob $job
- */
- private $job;
+class TestTimedJobNew extends \OCP\BackgroundJob\TimedJob {
+ /** @var bool */
+ public $ran = false;
- private $jobRun = false;
+ public function __construct(ITimeFactory $timeFactory) {
+ parent::__construct($timeFactory);
+ $this->setInterval(10);
+ }
- public function markRun() {
- $this->jobRun = true;
+ public function run($argument) {
+ $this->ran = true;
}
+}
+
+class TimedJobTest extends \Test\TestCase {
+ /** @var DummyJobList $jobList */
+ private $jobList;
+
+ /** @var ITimeFactory */
+ private $time;
protected function setup() {
parent::setUp();
$this->jobList = new DummyJobList();
- $this->job = new TestTimedJob($this);
- $this->jobList->add($this->job);
- $this->jobRun = false;
+ $this->time = \OC::$server->query(ITimeFactory::class);
}
public function testShouldRunAfterInterval() {
- $this->job->setLastRun(time() - 12);
- $this->job->execute($this->jobList);
- $this->assertTrue($this->jobRun);
+ $job = new TestTimedJob();
+ $this->jobList->add($job);
+
+ $job->setLastRun(time() - 12);
+ $job->execute($this->jobList);
+ $this->assertTrue($job->ran);
}
public function testShouldNotRunWithinInterval() {
- $this->job->setLastRun(time() - 5);
- $this->job->execute($this->jobList);
- $this->assertFalse($this->jobRun);
+ $job = new TestTimedJob();
+ $this->jobList->add($job);
+
+ $job->setLastRun(time() - 5);
+ $job->execute($this->jobList);
+ $this->assertFalse($job->ran);
}
public function testShouldNotTwice() {
- $this->job->setLastRun(time() - 15);
- $this->job->execute($this->jobList);
- $this->assertTrue($this->jobRun);
- $this->jobRun = false;
- $this->job->execute($this->jobList);
- $this->assertFalse($this->jobRun);
+ $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->execute($this->jobList);
+ $this->assertTrue($job->ran);
+ }
+
+ public function testShouldNotRunWithinIntervalNew() {
+ $job = new TestTimedJobNew($this->time);
+ $job->setId(42);
+ $this->jobList->add($job);
+
+ $job->setLastRun(time() - 5);
+ $job->execute($this->jobList);
+ $this->assertFalse($job->ran);
+ }
+
+ public function testShouldNotTwiceNew() {
+ $job = new TestTimedJobNew($this->time);
+ $job->setId(42);
+ $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);
}
}