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:
Diffstat (limited to 'spec/workers/authorized_project_update')
-rw-r--r--spec/workers/authorized_project_update/project_recalculate_worker_spec.rb68
-rw-r--r--spec/workers/authorized_project_update/user_refresh_from_replica_worker_spec.rb11
-rw-r--r--spec/workers/authorized_project_update/user_refresh_over_user_range_worker_spec.rb58
3 files changed, 98 insertions, 39 deletions
diff --git a/spec/workers/authorized_project_update/project_recalculate_worker_spec.rb b/spec/workers/authorized_project_update/project_recalculate_worker_spec.rb
new file mode 100644
index 00000000000..403793a15e2
--- /dev/null
+++ b/spec/workers/authorized_project_update/project_recalculate_worker_spec.rb
@@ -0,0 +1,68 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe AuthorizedProjectUpdate::ProjectRecalculateWorker do
+ include ExclusiveLeaseHelpers
+
+ let_it_be(:project) { create(:project) }
+
+ subject(:worker) { described_class.new }
+
+ it 'is labeled as high urgency' do
+ expect(described_class.get_urgency).to eq(:high)
+ end
+
+ include_examples 'an idempotent worker' do
+ let(:job_args) { project.id }
+
+ it 'does not change authorizations when run twice' do
+ user = create(:user)
+ project.add_developer(user)
+
+ user.project_authorizations.delete_all
+
+ expect { worker.perform(project.id) }.to change { project.project_authorizations.reload.size }.by(1)
+ expect { worker.perform(project.id) }.not_to change { project.project_authorizations.reload.size }
+ end
+ end
+
+ describe '#perform' do
+ it 'does not fail if the project does not exist' do
+ expect do
+ worker.perform(non_existing_record_id)
+ end.not_to raise_error
+ end
+
+ it 'calls AuthorizedProjectUpdate::ProjectRecalculateService' do
+ expect_next_instance_of(AuthorizedProjectUpdate::ProjectRecalculateService, project) do |service|
+ expect(service).to receive(:execute)
+ end
+
+ worker.perform(project.id)
+ end
+
+ context 'exclusive lease' do
+ let(:lock_key) { "#{described_class.name.underscore}/#{project.root_namespace.id}" }
+ let(:timeout) { 10.seconds }
+
+ context 'when exclusive lease has not been taken' do
+ it 'obtains a new exclusive lease' do
+ expect_to_obtain_exclusive_lease(lock_key, timeout: timeout)
+
+ worker.perform(project.id)
+ end
+ end
+
+ context 'when exclusive lease has already been taken' do
+ before do
+ stub_exclusive_lease_taken(lock_key, timeout: timeout)
+ end
+
+ it 'raises an error' do
+ expect { worker.perform(project.id) }.to raise_error(Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/workers/authorized_project_update/user_refresh_from_replica_worker_spec.rb b/spec/workers/authorized_project_update/user_refresh_from_replica_worker_spec.rb
new file mode 100644
index 00000000000..cdf2cb493b0
--- /dev/null
+++ b/spec/workers/authorized_project_update/user_refresh_from_replica_worker_spec.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe AuthorizedProjectUpdate::UserRefreshFromReplicaWorker do
+ it 'is labeled as low urgency' do
+ expect(described_class.get_urgency).to eq(:low)
+ end
+
+ it_behaves_like "refreshes user's project authorizations"
+end
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 832d5afd957..7c0c4d5bab4 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,7 +3,8 @@
require 'spec_helper'
RSpec.describe AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker do
- let(:project) { create(:project) }
+ let_it_be(:project) { create(:project) }
+
let(:user) { project.namespace.owner }
let(:start_user_id) { user.id }
let(:end_user_id) { start_user_id }
@@ -11,56 +12,35 @@ RSpec.describe AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker do
it_behaves_like 'worker with data consistency',
described_class,
- feature_flag: :delayed_consistency_for_user_refresh_over_range_worker,
data_consistency: :delayed
describe '#perform' do
- 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
+ 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
- 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
- execute_worker
- 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
- 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)
+ 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
+ execute_worker
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
+ 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