blob: e58af1d60fed67c3c89aeb46fef270dbb46e4844 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::SidekiqMiddleware::QueryAnalyzer, query_analyzers: false do
describe 'the PreventCrossDatabaseModification' do
describe '#call' do
let(:worker) { double(:worker) }
let(:job) { { 'jid' => 'job123' } }
let(:queue) { 'some-queue' }
let(:middleware) { described_class.new }
def do_queries
end
subject { middleware.call(worker, job, queue) { do_queries } }
context 'when there is a cross modification' do
def do_queries
Project.transaction do
Project.where(id: -1).update_all(id: -1)
::Ci::Pipeline.where(id: -1).update_all(id: -1)
end
end
it 'detects cross modifications and tracks exception' do
expect(::Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception)
subject
end
context 'when the detect_cross_database_modification is disabled' do
before do
stub_feature_flags(detect_cross_database_modification: false)
end
it 'does not detect cross modifications' do
expect(::Gitlab::ErrorTracking).not_to receive(:track_and_raise_for_dev_exception)
subject
end
end
end
context 'when there is no cross modification' do
def do_queries
Project.transaction do
Project.where(id: -1).update_all(id: -1)
Namespace.where(id: -1).update_all(id: -1)
end
end
it 'does not log anything' do
expect(::Gitlab::ErrorTracking).not_to receive(:track_and_raise_for_dev_exception)
subject
end
end
end
end
end
|