Skip to content

Commit

Permalink
MAGETWO-80644: FIX for #11166 Index Handling Fatal Error #11183
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksii Korshenko authored Oct 11, 2017
2 parents a6b7793 + 730a0e5 commit e6157bf
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/code/Magento/Indexer/Model/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,11 @@ public function reindexAll()
$state->save();
$this->getView()->resume();
throw $exception;
} catch (\Error $error) {
$state->setStatus(StateInterface::STATUS_INVALID);
$state->save();
$this->getView()->resume();
throw $error;
}
}
}
Expand Down
50 changes: 50 additions & 0 deletions app/code/Magento/Indexer/Test/Unit/Model/IndexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,56 @@ function () {
$this->model->reindexAll();
}

/**
* @expectedException \Error
* @expectedExceptionMessage Test Engine Error
*/
public function testReindexAllWithError()
{

$indexId = 'indexer_internal_name';
$this->loadIndexer($indexId);

$stateMock = $this->createPartialMock(
\Magento\Indexer\Model\Indexer\State::class,
['load', 'getId', 'setIndexerId', '__wakeup', 'getStatus', 'setStatus', 'save']
);
$stateMock->expects($this->once())->method('load')->with($indexId, 'indexer_id')->will($this->returnSelf());
$stateMock->expects($this->never())->method('setIndexerId');
$stateMock->expects($this->once())->method('getId')->will($this->returnValue(1));
$stateMock->expects($this->exactly(2))->method('setStatus')->will($this->returnSelf());
$stateMock->expects($this->once())->method('getStatus')->will($this->returnValue('idle'));
$stateMock->expects($this->exactly(2))->method('save')->will($this->returnSelf());
$this->stateFactoryMock->expects($this->once())->method('create')->will($this->returnValue($stateMock));

$this->viewMock->expects($this->once())->method('isEnabled')->will($this->returnValue(false));
$this->viewMock->expects($this->never())->method('suspend');
$this->viewMock->expects($this->once())->method('resume');

$actionMock = $this->createPartialMock(
\Magento\Framework\Indexer\ActionInterface::class,
['executeFull', 'executeList', 'executeRow']
);
$actionMock->expects($this->once())->method('executeFull')->will(
$this->returnCallback(
function () {
throw new \Error('Test Engine Error');
}
)
);
$this->actionFactoryMock->expects(
$this->once()
)->method(
'create'
)->with(
'Some\Class\Name'
)->will(
$this->returnValue($actionMock)
);

$this->model->reindexAll();
}

protected function getIndexerData()
{
return [
Expand Down

0 comments on commit e6157bf

Please sign in to comment.