Skip to content

Commit

Permalink
ENGCOM-902: [Backport 2.1] Schedule generation was broken #14096
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Idolov authored Mar 16, 2018
2 parents e08ded8 + 3e36723 commit 19c8770
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,6 @@ protected function saveSchedule($jobCode, $cronExpression, $timeInterval, $exist
if ($schedule->trySchedule()) {
// time matches cron expression
$schedule->save();
return;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,23 +530,19 @@ public function testDispatchGenerate()
{
$jobConfig = [
'test_group' => [
'default' => [
'test_job1' => [
'instance' => 'CronJob',
'method' => 'execute',
],
'test_job1' => [
'instance' => 'CronJob',
'method' => 'execute',
],
],
];

$this->_config->expects($this->at(0))->method('getJobs')->will($this->returnValue($jobConfig));
$jobs = [
'test_group' => [
'default' => [
'job1' => ['config_path' => 'test/path'],
'job2' => ['schedule' => ''],
'job3' => ['schedule' => '* * * * *'],
],
'job1' => ['config_path' => 'test/path'],
'job2' => ['schedule' => ''],
'job3' => ['schedule' => '* * * * *'],
],
];
$this->_config->expects($this->at(1))->method('getJobs')->will($this->returnValue($jobs));
Expand All @@ -570,32 +566,40 @@ public function testDispatchGenerate()
$this->returnValue(time() + 10000000)
);

$this->_scopeConfig->expects($this->at(0))->method('getValue')->will($this->returnValue(0));
$this->_scopeConfig->expects($this->any())->method('getValue')->willReturnMap(
[
[
'system/cron/test_group/schedule_generate_every',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
null,
0
],
[
'system/cron/test_group/schedule_ahead_for',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
null,
2
]
]
);

$scheduleMethods = ['getJobCode', 'getScheduledAt', 'trySchedule', 'unsScheduleId', 'save', '__wakeup'];
$schedule = $this->getMockBuilder(
'Magento\Cron\Model\Schedule'
)->setMethods(
$scheduleMethods
['getJobCode', 'getScheduledAt', 'trySchedule', 'unsScheduleId', 'save', '__wakeup', 'getCollection']
)->disableOriginalConstructor()->getMock();
$schedule->expects($this->any())->method('getJobCode')->will($this->returnValue('job_code1'));
$schedule->expects($this->once())->method('getScheduledAt')->will($this->returnValue('* * * * *'));
$schedule->expects($this->any())->method('unsScheduleId')->will($this->returnSelf());
$schedule->expects($this->any())->method('trySchedule')->will($this->returnSelf());
$schedule->expects($this->any())->method('getCollection')->willReturn($this->_collection);
$schedule->expects($this->atLeastOnce())->method('save')->willReturnSelf();

$this->_collection->addItem(new \Magento\Framework\DataObject());
$this->_collection->addItem($schedule);

$this->_cache->expects($this->any())->method('save');

$scheduleMock = $this->getMockBuilder(
'Magento\Cron\Model\Schedule'
)->disableOriginalConstructor()->setMethods(
['getCollection', '__wakeup']
)->getMock();
$scheduleMock->expects($this->any())->method('getCollection')->will($this->returnValue($this->_collection));
$this->_scheduleFactory->expects($this->any())->method('create')->will($this->returnValue($scheduleMock));

$this->_scheduleFactory->expects($this->any())->method('create')->will($this->returnValue($schedule));

$this->_observer->execute($this->observer);
Expand Down

0 comments on commit 19c8770

Please sign in to comment.