Commit 4455af17 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'move_lb_user_activity_service' into 'master'

Move non-sticky call in Users::ActivityService to Core

See merge request gitlab-org/gitlab!62746
parents 33a0edc8 7308eda4
......@@ -17,7 +17,7 @@ module Users
def execute
return unless @user
record_activity
::Gitlab::Database::LoadBalancing::Session.without_sticky_writes { record_activity }
end
private
......@@ -37,5 +37,3 @@ module Users
end
end
end
Users::ActivityService.prepend_mod
# frozen_string_literal: true
module EE
module Users
module ActivityService
extend ::Gitlab::Utils::Override
private
override :record_activity
def record_activity
::Gitlab::Database::LoadBalancing::Session.without_sticky_writes { super }
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Users::ActivityService, '#execute', :request_store, :redis, :clean_gitlab_redis_shared_state do
include_context 'clear DB Load Balancing configuration'
let(:user) { create(:user, last_activity_on: last_activity_on) }
context 'when last activity is in the past' do
let(:user) { create(:user, last_activity_on: Date.today - 1.week) }
context 'database load balancing is configured' do
before do
# Do not pollute AR for other tests, but rather simulate effect of configure_proxy.
allow(ActiveRecord::Base.singleton_class).to receive(:prepend)
::Gitlab::Database::LoadBalancing.configure_proxy
allow(ActiveRecord::Base).to receive(:connection).and_return(::Gitlab::Database::LoadBalancing.proxy)
end
let(:service) do
service = described_class.new(user)
::Gitlab::Database::LoadBalancing::Session.clear_session
service
end
it 'does not stick to primary' do
expect(::Gitlab::Database::LoadBalancing::Session.current).not_to be_performed_write
service.execute
expect(user.last_activity_on).to eq(Date.today)
expect(::Gitlab::Database::LoadBalancing::Session.current).to be_performed_write
expect(::Gitlab::Database::LoadBalancing::Session.current).not_to be_using_primary
end
end
context 'database load balancing is not configured' do
let(:service) { described_class.new(user) }
it 'updates user without error' do
service.execute
expect(user.last_activity_on).to eq(Date.today)
end
end
end
end
......@@ -84,4 +84,51 @@ RSpec.describe Users::ActivityService do
end
end
end
context 'with DB Load Balancing', :request_store, :redis, :clean_gitlab_redis_shared_state do
include_context 'clear DB Load Balancing configuration'
let(:user) { create(:user, last_activity_on: last_activity_on) }
context 'when last activity is in the past' do
let(:user) { create(:user, last_activity_on: Date.today - 1.week) }
context 'database load balancing is configured' do
before do
# Do not pollute AR for other tests, but rather simulate effect of configure_proxy.
allow(ActiveRecord::Base.singleton_class).to receive(:prepend)
::Gitlab::Database::LoadBalancing.configure_proxy
allow(ActiveRecord::Base).to receive(:connection).and_return(::Gitlab::Database::LoadBalancing.proxy)
end
let(:service) do
service = described_class.new(user)
::Gitlab::Database::LoadBalancing::Session.clear_session
service
end
it 'does not stick to primary' do
expect(::Gitlab::Database::LoadBalancing::Session.current).not_to be_performed_write
service.execute
expect(user.last_activity_on).to eq(Date.today)
expect(::Gitlab::Database::LoadBalancing::Session.current).to be_performed_write
expect(::Gitlab::Database::LoadBalancing::Session.current).not_to be_using_primary
end
end
context 'database load balancing is not configured' do
let(:service) { described_class.new(user) }
it 'updates user without error' do
service.execute
expect(user.last_activity_on).to eq(Date.today)
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