Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync command stop-on-error flag #3500

Merged
merged 16 commits into from
Aug 3, 2023
Merged
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
Prev Previous commit
Next Next commit
Rollback test approach
  • Loading branch information
oscarssanchez committed Aug 3, 2023
commit 417fb94190a94cff6c2578f88dcc2ce20aaa0d4a
66 changes: 34 additions & 32 deletions tests/php/TestCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -936,43 +936,45 @@ public function testRequest() {
* @since 4.7.0
*/
public function test_sync_stop_on_error() {
$elasticsearch_mock = $this->getMockBuilder( \ElasticPress\IndexHelper::class )
->setMethods( [ 'bulk_index_dynamically' ] )
->getMock();

$fake_request = [
'errors' => true,
'items' => [
[
'index' => [
'error' => [
'reason' => 'my dummy error reason',
'type' => 'my dummy error type'
],
'status' => 400,
'_id' => '10',
'type' => '_doc',
'_index' => 'dummy-index'
]
]
]
];
add_filter(
'http_response',
function( $request ) {
$fake_request = json_decode( wp_remote_retrieve_body( $request ) );

if ( ! empty( $fake_request->items ) ) {
$fake_request->errors = true;

$fake_item = new \stdClass();
$fake_item->index = new \stdClass();
$fake_item->index->error = new \stdClass();
$fake_item->index->status = 400;
$fake_item->index->_id = 10;
$fake_item->index->type = '_doc';
$fake_item->index->_index = 'dummy-index';
$fake_item->index->error->reason = 'my dummy error reason';
$fake_item->index->error->type = 'my dummy error type';

$fake_request->items[0] = $fake_item;

$request['body'] = wp_json_encode( $fake_request );

return $request;
}

$elasticsearch_mock->expects( $this->exactly( 1 ) )
->method( 'bulk_index_dynamically' )
->willReturn( $fake_request );
return $request;
}
);
Indexables::factory()->get( 'post' )->delete_index();

$index_args = [
'method' => 'cli',
'output_method' => [ $this->command, 'index_output' ],
'stop_on_error' => true,
'show-errors' => false
];
$this->ep_factory->post->create_many( 1 );

$this->expectExceptionMessage( '10 (Post): [my dummy error type] my dummy error reason' );

ElasticPress\IndexHelper::factory()->full_index(
$index_args
$this->command->sync(
[],
[
'stop-on-error' => true,
]
);
}

Expand Down