-
Notifications
You must be signed in to change notification settings - Fork 369
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
Raise error in #scroll_batches when search backend returns a failure #916
base: master
Are you sure you want to change the base?
Changes from 2 commits
040d857
fc46a0e
3aa2bc1
467974f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -34,6 +34,9 @@ def scroll_batches(batch_size: Request::DEFAULT_BATCH_SIZE, scroll: Request::DEF | |||||||||||||||||||||||||||
scroll_id = nil | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
loop do | ||||||||||||||||||||||||||||
failures = result.dig('_shards', 'failures') | ||||||||||||||||||||||||||||
tomdev marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
raise Chewy::Error, failures if failures.present? | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think Lines 20 to 32 in 10ff43b
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
hits = result.fetch('hits', {}).fetch('hits', []) | ||||||||||||||||||||||||||||
fetched += hits.size | ||||||||||||||||||||||||||||
hits = hits.first(last_batch_size) if last_batch_size != 0 && fetched >= total | ||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,56 @@ | |
let(:countries) { Array.new(3) { |i| Country.create!(rating: i + 2, name: "country #{i}") } } | ||
|
||
describe '#scroll_batches' do | ||
describe 'with search backend returning failures' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw, do you think it will be possible to provide integration spec? Where you really call ES and get real answer? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have a suggestion how I can set up an integration spec that returns this error state? Elasticsearch should return a total count higher than zero but then return zero hits in order to hit this code path. |
||
before do | ||
expect(Chewy.client).to receive(:scroll).once.and_return( | ||
'hits' => { | ||
'total' => { | ||
'value' => 5 | ||
}, | ||
'hits' => [] | ||
}, | ||
'_shards' => { | ||
'total' => 5, | ||
'successful' => 2, | ||
'skipped' => 0, | ||
'failed' => 3, | ||
'failures' => [ | ||
{ | ||
'shard' => -1, | ||
'index' => nil, | ||
'reason' => { | ||
'type' => 'search_context_missing_exception', | ||
'reason' => 'No search context found for id [34462229]' | ||
} | ||
}, | ||
{ | ||
'shard' => -1, | ||
'index' => nil, | ||
'reason' => { | ||
'type' => 'search_context_missing_exception', | ||
'reason' => 'No search context found for id [34462228]' | ||
} | ||
}, | ||
{ | ||
'shard' => -1, | ||
'index' => nil, | ||
'reason' => { | ||
'type' => 'search_context_missing_exception', | ||
'reason' => 'No search context found for id [34888662]' | ||
} | ||
} | ||
] | ||
}, | ||
'_scroll_id' => 'scroll_id' | ||
) | ||
end | ||
|
||
specify do | ||
expect { request.scroll_batches(batch_size: 2) {} }.to raise_error(Chewy::Error) | ||
end | ||
end | ||
|
||
context do | ||
before { expect(Chewy.client).to receive(:scroll).twice.and_call_original } | ||
specify do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, could we remove this? I planning to backport docker-compose setup with ES, so it runs on proper port /~https://github.com/toptal/chewy/pull/917/files#diff-e45e45baeda1c1e73482975a664062aa56f20c03dd9d64a827aba57775bed0d3R1-R16
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course, done!