Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-06-01 21:10:04 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-06-01 21:10:04 +0300
commitc3afdb42ddc7f24d51032ed0daef071a2dafdc93 (patch)
tree4bf3f4fed99d260370921dd2c222840012be14a3 /spec/services/user_project_access_changed_service_spec.rb
parent41aebff8ec728c167298aa44e037d8e324e00e8d (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/user_project_access_changed_service_spec.rb')
-rw-r--r--spec/services/user_project_access_changed_service_spec.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/services/user_project_access_changed_service_spec.rb b/spec/services/user_project_access_changed_service_spec.rb
index 070782992e7..28d9fa85c7e 100644
--- a/spec/services/user_project_access_changed_service_spec.rb
+++ b/spec/services/user_project_access_changed_service_spec.rb
@@ -31,4 +31,37 @@ RSpec.describe UserProjectAccessChangedService do
priority: described_class::LOW_PRIORITY)
end
end
+
+ context 'with load balancing enabled' do
+ let(:service) { UserProjectAccessChangedService.new([1, 2]) }
+
+ before do
+ allow(Gitlab::Database::LoadBalancing).to receive(:enable?).and_return(true)
+
+ expect(AuthorizedProjectsWorker).to receive(:bulk_perform_and_wait)
+ .with([[1], [2]])
+ .and_return(10)
+ end
+
+ it 'sticks all the updated users and returns the original result', :aggregate_failures do
+ expect(Gitlab::Database::LoadBalancing::Sticking).to receive(:bulk_stick).with(:user, [1, 2])
+
+ expect(service.execute).to eq(10)
+ end
+
+ it 'avoids N+1 cached queries', :use_sql_query_cache, :request_store do
+ # Run this once to establish a baseline
+ control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) do
+ service.execute
+ end
+
+ service = UserProjectAccessChangedService.new([1, 2, 3, 4, 5])
+
+ allow(AuthorizedProjectsWorker).to receive(:bulk_perform_and_wait)
+ .with([[1], [2], [3], [4], [5]])
+ .and_return(10)
+
+ expect { service.execute }.not_to exceed_all_query_limit(control_count.count)
+ end
+ end
end