Skip to content

Commit

Permalink
test(QueuedJobService) Added testcase for memory expired broken job
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus Nyeholt committed Feb 7, 2017
1 parent 4072408 commit f17a1b9
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/QueuedJobsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,26 @@ public function testJobHealthCheck() {
$this->assertEquals(QueuedJob::STATUS_PAUSED, $descriptor->JobStatus);
$this->assertEmpty($nextJob);
}

public function testExceptionWithMemoryExhaustion() {
$svc = $this->getService();
$job = new TestExceptingJob();
$job->firstJob = true;
$id = $svc->queueJob($job);
$descriptor = QueuedJobDescriptor::get()->byID($id);

// we want to set the memory limit _really_ low so that our first run triggers
$mem = Config::inst()->get('QueuedJobService', 'memory_limit');
Config::inst()->update('QueuedJobService', 'memory_limit', 1);

$svc->runJob($id);

Config::inst()->update('QueuedJobService', 'memory_limit', $mem);

$descriptor = QueuedJobDescriptor::get()->byID($id);

$this->assertEquals(QueuedJob::STATUS_BROKEN, $descriptor->JobStatus);
}
}

// stub class to be able to call init from an external context
Expand All @@ -365,6 +385,31 @@ public function testInit($descriptor) {
}
}

class TestExceptingJob extends AbstractQueuedJob implements QueuedJob {
private $type = QueuedJob::QUEUED;

public function __construct($type = null) {
$this->type = QueuedJob::IMMEDIATE;
$this->times = array();
}

public function getJobType() {
return $this->type;
}

public function getTitle() {
return "A Test job throwing exceptions";
}

public function setup() {
$this->totalSteps = 1;
}

public function process() {
throw new Exception("just excepted");
}
}

class TestQueuedJob extends AbstractQueuedJob implements QueuedJob {
private $type = QueuedJob::QUEUED;

Expand Down

0 comments on commit f17a1b9

Please sign in to comment.