Commit e431ed9d authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'mk/fix-primary-verification' into 'master'

Geo: Fix repository verification on the primary

Closes #213523

See merge request gitlab-org/gitlab!28893
parents e7a12d06 70f7799e
---
title: 'Geo: Fix repository verification on the primary'
merge_request: 28893
author:
type: fixed
......@@ -25,11 +25,13 @@ module EE
ActiveRecord::Base.establish_connection(config)
end
def geo_uncached_queries
def geo_uncached_queries(&block)
raise 'No block given' unless block_given?
Geo::TrackingBase.uncached do
ActiveRecord::Base.uncached do
ActiveRecord::Base.uncached do
if ::Gitlab::Geo.secondary?
Geo::TrackingBase.uncached(&block)
else
yield
end
end
......
......@@ -3,6 +3,8 @@
require 'spec_helper'
describe Gitlab::Database do
include ::EE::GeoHelpers
describe '.read_only?' do
context 'with Geo enabled' do
before do
......@@ -64,4 +66,56 @@ describe Gitlab::Database do
expect(config['prepared_statements']).to eq(false)
end
end
describe '.geo_uncached_queries' do
context 'when no block is given' do
it 'raises error' do
expect do
described_class.geo_uncached_queries
end.to raise_error('No block given')
end
end
context 'when the current node is a primary' do
let!(:primary) { create(:geo_node, :primary) }
it 'wraps the block in an ActiveRecord::Base.uncached block' do
stub_current_geo_node(primary)
expect(Geo::TrackingBase).not_to receive(:uncached)
expect(ActiveRecord::Base).to receive(:uncached).and_call_original
expect do |b|
described_class.geo_uncached_queries(&b)
end.to yield_control
end
end
context 'when the current node is a secondary' do
let!(:primary) { create(:geo_node, :primary) }
let!(:secondary) { create(:geo_node) }
it 'wraps the block in a Geo::TrackingBase.uncached block and an ActiveRecord::Base.uncached block' do
stub_current_geo_node(secondary)
expect(Geo::TrackingBase).to receive(:uncached).and_call_original
expect(ActiveRecord::Base).to receive(:uncached).and_call_original
expect do |b|
described_class.geo_uncached_queries(&b)
end.to yield_control
end
end
context 'when there is no current node' do
it 'wraps the block in an ActiveRecord::Base.uncached block' do
expect(Geo::TrackingBase).not_to receive(:uncached)
expect(ActiveRecord::Base).to receive(:uncached).and_call_original
expect do |b|
described_class.geo_uncached_queries(&b)
end.to yield_control
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