Commit 999ba7c1 authored by Ethan Urie's avatar Ethan Urie

Merge branch '338004-fix-retry-mechanism-batched' into 'master'

Fix BackgroundMigration::BackfillWorkItemTypeIdForIssues

See merge request gitlab-org/gitlab!83662
parents ebd362ee 72b1910b
...@@ -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