diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-16 21:09:14 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-16 21:09:14 +0300 |
commit | ac99f7b78181f31d4b41b74b04038d11881aaa7f (patch) | |
tree | 7e5f54056bb49c99e8a9742516a03628ad0bdee5 /spec | |
parent | 7f70c3a95c6c7635234b822bc50b6d476a4d9929 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/services/authorized_project_update/find_records_due_for_refresh_service_spec.rb | 35 | ||||
-rw-r--r-- | spec/workers/authorized_project_update/user_refresh_over_user_range_worker_spec.rb | 63 |
2 files changed, 92 insertions, 6 deletions
diff --git a/spec/services/authorized_project_update/find_records_due_for_refresh_service_spec.rb b/spec/services/authorized_project_update/find_records_due_for_refresh_service_spec.rb index cdc93eaa365..8a53d9fbf7c 100644 --- a/spec/services/authorized_project_update/find_records_due_for_refresh_service_spec.rb +++ b/spec/services/authorized_project_update/find_records_due_for_refresh_service_spec.rb @@ -94,6 +94,41 @@ RSpec.describe AuthorizedProjectUpdate::FindRecordsDueForRefreshService do end end + describe '#needs_refresh?' do + subject { service.needs_refresh? } + + context 'when there are records due for either removal or addition' do + context 'when there are both removals and additions to be made' do + before do + user.project_authorizations.delete_all + create(:project_authorization, user: user) + end + + it { is_expected.to eq(true) } + end + + context 'when there are no removals, but there are additions to be made' do + before do + user.project_authorizations.delete_all + end + + it { is_expected.to eq(true) } + end + + context 'when there are no additions, but there are removals to be made' do + before do + create(:project_authorization, user: user) + end + + it { is_expected.to eq(true) } + end + end + + context 'when there are no additions or removals to be made' do + it { is_expected.to eq(false) } + end + end + describe '#fresh_access_levels_per_project' do let(:hash) { service.fresh_access_levels_per_project } diff --git a/spec/workers/authorized_project_update/user_refresh_over_user_range_worker_spec.rb b/spec/workers/authorized_project_update/user_refresh_over_user_range_worker_spec.rb index a27c431523e..0501fc3b8cf 100644 --- a/spec/workers/authorized_project_update/user_refresh_over_user_range_worker_spec.rb +++ b/spec/workers/authorized_project_update/user_refresh_over_user_range_worker_spec.rb @@ -3,16 +3,67 @@ require 'spec_helper' RSpec.describe AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker do - let(:start_user_id) { 42 } - let(:end_user_id) { 4242 } + let(: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) } + + it_behaves_like 'worker with data consistency', + described_class, + feature_flag: :periodic_project_authorization_update_via_replica, + data_consistency: :delayed describe '#perform' do - it 'calls AuthorizedProjectUpdate::RecalculateForUserRangeService' do - expect_next_instance_of(AuthorizedProjectUpdate::RecalculateForUserRangeService) do |service| - expect(service).to receive(:execute) + context 'when the feature flag `periodic_project_authorization_update_via_replica` is enabled' do + before do + stub_feature_flags(periodic_project_authorization_update_via_replica: true) + end + + context 'checks if project authorization update is required' do + it 'checks if a project_authorization refresh is needed for each of the users' do + User.where(id: start_user_id..end_user_id).each do |user| + expect(AuthorizedProjectUpdate::FindRecordsDueForRefreshService).to( + receive(:new).with(user).and_call_original) + end + + execute_worker + end + end + + context 'when there are project authorization records due for either removal or addition for a specific user' do + before do + user.project_authorizations.delete_all + end + + it 'enqueues a new project authorization update job for the user' do + expect(AuthorizedProjectUpdate::UserRefreshWithLowUrgencyWorker).to receive(:perform_async).with(user.id) + + execute_worker + end end - subject.perform(start_user_id, end_user_id) + context 'when there are no additions or removals to be made to project authorizations for a specific user' do + it 'does not enqueue a new project authorization update job for the user' do + expect(AuthorizedProjectUpdate::UserRefreshWithLowUrgencyWorker).not_to receive(:perform_async) + + execute_worker + end + end + end + + 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 + + it 'calls AuthorizedProjectUpdate::RecalculateForUserRangeService' do + expect_next_instance_of(AuthorizedProjectUpdate::RecalculateForUserRangeService, start_user_id, end_user_id) do |service| + expect(service).to receive(:execute) + end + + execute_worker + end end end end |