Commit 6030d99d authored by Doug Stull's avatar Doug Stull

Merge branch '350092_fix_cross_database_transaction_in_specs' into 'master'

Fix cross-database data moditifaction in IngestReportSliceService spec

See merge request gitlab-org/gitlab!79504
parents 1c10a25c fb8bc5d8
...@@ -32,10 +32,8 @@ module Security ...@@ -32,10 +32,8 @@ module Security
end end
def execute def execute
::Gitlab::Database::QueryAnalyzers::PreventCrossDatabaseModification.allow_cross_database_modification_within_transaction(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/350092') do ApplicationRecord.transaction do
ApplicationRecord.transaction do TASKS.each { |task| execute_task(task) }
TASKS.each { |task| execute_task(task) }
end
end end
@finding_maps.map(&:vulnerability_id) @finding_maps.map(&:vulnerability_id)
......
...@@ -38,9 +38,10 @@ RSpec.describe Security::Ingestion::IngestReportSliceService do ...@@ -38,9 +38,10 @@ RSpec.describe Security::Ingestion::IngestReportSliceService do
context 'when an exception happens' do context 'when an exception happens' do
let(:mock_task_1) { double(:task) } let(:mock_task_1) { double(:task) }
let(:mock_task_2) { double(:task) } let(:mock_task_2) { double(:task) }
let(:security_finding) { finding_maps.first.security_finding }
before do before do
allow(mock_task_1).to receive(:execute) { |pipeline, *| pipeline.update_column(:updated_at, 3.months.from_now) } allow(mock_task_1).to receive(:execute) { |pipeline, *| security_finding.update_column(:uuid, SecureRandom.uuid) }
allow(mock_task_2).to receive(:execute) { raise 'foo' } allow(mock_task_2).to receive(:execute) { raise 'foo' }
allow(Security::Ingestion::Tasks).to receive(:const_get).with(:IngestIdentifiers, false).and_return(mock_task_1) allow(Security::Ingestion::Tasks).to receive(:const_get).with(:IngestIdentifiers, false).and_return(mock_task_1)
...@@ -49,7 +50,7 @@ RSpec.describe Security::Ingestion::IngestReportSliceService do ...@@ -49,7 +50,7 @@ RSpec.describe Security::Ingestion::IngestReportSliceService do
it 'rollsback the recent changes to not to leave the database in an inconsistent state' do it 'rollsback the recent changes to not to leave the database in an inconsistent state' do
expect { ingest_report_slice }.to raise_error('foo') expect { ingest_report_slice }.to raise_error('foo')
.and not_change { pipeline.reload.updated_at } .and not_change { security_finding.reload.uuid }
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