Commit f95e3544 authored by David Fernandez's avatar David Fernandez

Merge branch '352300-import-api-transactions' into 'master'

Move registry import API calls outside of transaction

See merge request gitlab-org/gitlab!80509
parents 34f2e497 490f6f65
......@@ -79,7 +79,7 @@ class ContainerRepository < ApplicationRecord
)
end
state_machine :migration_state, initial: :default do
state_machine :migration_state, initial: :default, use_transactions: false do
state :pre_importing do
validates :migration_pre_import_started_at, presence: true
validates :migration_pre_import_done_at, presence: false
......
......@@ -339,6 +339,55 @@ RSpec.describe ContainerRepository, :aggregate_failures do
end
end
context 'when triggering registry API requests' do
let(:repository_state) { nil }
let(:repository) { create(:container_repository, repository_state) }
shared_examples 'a state machine configured with use_transactions: false' do
it 'executes the registry API request outside of a transaction', :delete do
expect(repository).to receive(:save).and_call_original do
expect(ApplicationRecord.connection.transaction_open?).to be true
end
expect(repository).to receive(:try_import) do
expect(ApplicationRecord.connection.transaction_open?).to be false
end
subject
end
end
context 'when responding to a start_pre_import event' do
subject { repository.start_pre_import }
it_behaves_like 'a state machine configured with use_transactions: false'
end
context 'when responding to a retry_pre_import event' do
let(:repository_state) { :import_aborted }
subject { repository.retry_pre_import }
it_behaves_like 'a state machine configured with use_transactions: false'
end
context 'when responding to a start_import event' do
let(:repository_state) { :pre_import_done }
subject { repository.start_import }
it_behaves_like 'a state machine configured with use_transactions: false'
end
context 'when responding to a retry_import event' do
let(:repository_state) { :import_aborted }
subject { repository.retry_import }
it_behaves_like 'a state machine configured with use_transactions: false'
end
end
describe '#retry_aborted_migration' do
subject { repository.retry_aborted_migration }
......
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