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 ...@@ -48,7 +48,7 @@ module Gitlab
begin begin
update_batch(sub_batch, base_type_id) update_batch(sub_batch, base_type_id)
rescue ActiveRecord::StatementTimeout => e rescue ActiveRecord::StatementTimeout, ActiveRecord::QueryCanceled => e
update_attempt += 1 update_attempt += 1
if update_attempt <= MAX_UPDATE_RETRIES if update_attempt <= MAX_UPDATE_RETRIES
......
...@@ -48,12 +48,20 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillWorkItemTypeIdForIssues do ...@@ -48,12 +48,20 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillWorkItemTypeIdForIssues do
expect { migrate }.to change { migration.batch_metrics.timings } expect { migrate }.to change { migration.batch_metrics.timings }
end end
it 'retries on ActiveRecord::StatementTimeout' do context 'when database timeouts' do
expect(migration).to receive(:update_batch).exactly(3).times.and_raise(ActiveRecord::StatementTimeout) using RSpec::Parameterized::TableSyntax
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(migration).to receive(:sleep).with(30).twice
expect do expect do
migrate migrate
end.to raise_error(ActiveRecord::StatementTimeout) end.to raise_error(error_class)
end
end
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