Commit 9ac52bb4 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'if-215385-authorized_projects_worker_with_low_urgency' into 'master'

Add new authorized project worker with low priority

See merge request gitlab-org/gitlab!31072
parents 62e6ade0 3a565b3f
...@@ -927,6 +927,13 @@ ...@@ -927,6 +927,13 @@
:resource_boundary: :unknown :resource_boundary: :unknown
:weight: 2 :weight: 2
:idempotent: true :idempotent: true
- :name: authorized_project_update_user_refresh_with_low_urgency
:feature_category: :authentication_and_authorization
:has_external_dependencies:
:urgency: :low
:resource_boundary: :unknown
:weight: 1
:idempotent: true
- :name: authorized_projects - :name: authorized_projects
:feature_category: :authentication_and_authorization :feature_category: :authentication_and_authorization
:has_external_dependencies: :has_external_dependencies:
......
# frozen_string_literal: true
module AuthorizedProjectUpdate
class UserRefreshWithLowUrgencyWorker < ::AuthorizedProjectsWorker
feature_category :authentication_and_authorization
urgency :low
idempotent!
end
end
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
- 1 - 1
- - authorized_keys - - authorized_keys
- 2 - 2
- - authorized_project_update_user_refresh_with_low_urgency
- 1
- - authorized_projects - - authorized_projects
- 2 - 2
- - auto_devops - - auto_devops
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.shared_examples "refreshes user's project authorizations" do
describe '#perform' do
let(:user) { create(:user) }
subject(:job) { described_class.new }
it "refreshes user's authorized projects" do
expect_any_instance_of(User).to receive(:refresh_authorized_projects)
job.perform(user.id)
end
context "when the user is not found" do
it "does nothing" do
expect_any_instance_of(User).not_to receive(:refresh_authorized_projects)
job.perform(-1)
end
end
it_behaves_like "an idempotent worker" do
let(:job_args) { user.id }
it "does not change authorizations when run twice" do
group = create(:group)
create(:project, namespace: group)
group.add_developer(user)
# Delete the authorization created by the after save hook of the member
# created above.
user.project_authorizations.delete_all
expect { job.perform(user.id) }.to change { user.project_authorizations.reload.size }.by(1)
expect { job.perform(user.id) }.not_to change { user.project_authorizations.reload.size }
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe AuthorizedProjectUpdate::UserRefreshWithLowUrgencyWorker 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
...@@ -3,40 +3,5 @@ ...@@ -3,40 +3,5 @@
require 'spec_helper' require 'spec_helper'
describe AuthorizedProjectsWorker do describe AuthorizedProjectsWorker do
describe '#perform' do it_behaves_like "refreshes user's project authorizations"
let(:user) { create(:user) }
subject(:job) { described_class.new }
it "refreshes user's authorized projects" do
expect_any_instance_of(User).to receive(:refresh_authorized_projects)
job.perform(user.id)
end
context "when the user is not found" do
it "does nothing" do
expect_any_instance_of(User).not_to receive(:refresh_authorized_projects)
job.perform(-1)
end
end
it_behaves_like "an idempotent worker" do
let(:job_args) { user.id }
it "does not change authorizations when run twice" do
group = create(:group)
create(:project, namespace: group)
group.add_developer(user)
# Delete the authorization created by the after save hook of the member
# created above.
user.project_authorizations.delete_all
expect { job.perform(user.id) }.to change { user.project_authorizations.reload.size }.by(1)
expect { job.perform(user.id) }.not_to change { user.project_authorizations.reload.size }
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