Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • please add space before catch
  • is there more specific exception you can catch?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It not so easy to a more specific exception:
Currently, php7 throw much different but you must catch all to set the correct state for the indexer. After a fatal, the indexer must be on state invalid

php__errors_in_php_7_-_manual

$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