Commit 4c3edc88 authored by Thong Kuah's avatar Thong Kuah

Merge branch 'move_lb_user_refresh_worker' into 'master'

Move LB use_primary! call in worker to Core

See merge request gitlab-org/gitlab!62747
parents 5e7c03c5 42dea18d
...@@ -40,7 +40,9 @@ module AuthorizedProjectUpdate ...@@ -40,7 +40,9 @@ module AuthorizedProjectUpdate
private private
def use_primary_database def use_primary_database
# no-op in CE, overriden in EE if ::Gitlab::Database::LoadBalancing.enable?
::Gitlab::Database::LoadBalancing::Session.current.use_primary!
end
end end
def project_authorizations_needs_refresh?(user) def project_authorizations_needs_refresh?(user)
...@@ -54,5 +56,3 @@ module AuthorizedProjectUpdate ...@@ -54,5 +56,3 @@ module AuthorizedProjectUpdate
end end
end end
end end
AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker.prepend_mod_with('AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker')
# frozen_string_literal: true
module EE
module AuthorizedProjectUpdate
module UserRefreshOverUserRangeWorker # rubocop:disable Scalability/IdempotentWorker
extend ::Gitlab::Utils::Override
private
override :use_primary_database
def use_primary_database
if ::Gitlab::Database::LoadBalancing.enable?
::Gitlab::Database::LoadBalancing::Session.current.use_primary!
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker do
let_it_be(:project) { create(:project) }
let(:user) { project.namespace.owner }
let(:start_user_id) { user.id }
let(:end_user_id) { start_user_id }
let(:execute_worker) { subject.perform(start_user_id, end_user_id) }
describe '#perform' do
context 'when the feature flag `periodic_project_authorization_update_via_replica` is disabled' do
before do
stub_feature_flags(periodic_project_authorization_update_via_replica: false)
end
context 'when load balancing is enabled' do
before do
allow(Gitlab::Database::LoadBalancing).to receive(:enable?).and_return(true)
end
it 'reads from the primary database' do
expect(Gitlab::Database::LoadBalancing::Session.current)
.to receive(:use_primary!)
execute_worker
end
end
end
end
end
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker do RSpec.describe AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker do
let(:project) { create(:project) } let_it_be(:project) { create(:project) }
let(:user) { project.namespace.owner } let(:user) { project.namespace.owner }
let(:start_user_id) { user.id } let(:start_user_id) { user.id }
let(:end_user_id) { start_user_id } let(:end_user_id) { start_user_id }
...@@ -64,6 +65,18 @@ RSpec.describe AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker do ...@@ -64,6 +65,18 @@ RSpec.describe AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker do
execute_worker execute_worker
end end
context 'when load balancing is enabled' do
before do
allow(Gitlab::Database::LoadBalancing).to receive(:enable?).and_return(true)
end
it 'reads from the primary database' do
expect(Gitlab::Database::LoadBalancing::Session.current).to receive(:use_primary!)
execute_worker
end
end
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