Commit 72b1910b authored by Mario Celi's avatar Mario Celi

Fixes an error on BackgroundMigration::BackfillWorkItemTypeIdForIssues

A retry mechanism is in place as we expect queries to timeout.
The wrong exception was rescued. Before we rescued only from
ActiveRecord::StatementTimeout and now we also rescue
ActiveRecord::QueryCanceled
parent dd5332a4
......@@ -48,7 +48,7 @@ module Gitlab
begin
update_batch(sub_batch, base_type_id)
rescue ActiveRecord::StatementTimeout => e
rescue ActiveRecord::StatementTimeout, ActiveRecord::QueryCanceled => e
update_attempt += 1
if update_attempt <= MAX_UPDATE_RETRIES
......
......@@ -48,12 +48,20 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillWorkItemTypeIdForIssues do
expect { migrate }.to change { migration.batch_metrics.timings }
end
it 'retries on ActiveRecord::StatementTimeout' do
expect(migration).to receive(:update_batch).exactly(3).times.and_raise(ActiveRecord::StatementTimeout)
expect(migration).to receive(:sleep).with(30).twice
context 'when database timeouts' do
using RSpec::Parameterized::TableSyntax
expect do
migrate
end.to raise_error(ActiveRecord::StatementTimeout)
where(error_class: [ActiveRecord::StatementTimeout, ActiveRecord::QueryCanceled])
with_them do
it 'retries on timeout error' do
expect(migration).to receive(:update_batch).exactly(3).times.and_raise(error_class)
expect(migration).to receive(:sleep).with(30).twice
expect do
migrate
end.to raise_error(error_class)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment