Commit 490f6f65 authored by Steve Abrams's avatar Steve Abrams Committed by David Fernandez

Registry import API calls outside of transaction

Turn off transactions for callbacks that make API
calls to the registry during the container_repository
import transitions.
parent cf9fc53c
......@@ -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