Commit 63f4ea2d authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '218434-update-with_shared_runners_limit_enabled-scope' into 'master'

Update :with_shared_runners_limit_enabled scope

See merge request gitlab-org/gitlab!32648
parents 4962e83d c2491bea
......@@ -3,6 +3,8 @@
module EE
module Ci
module Runner
extend ActiveSupport::Concern
def tick_runner_queue
::Gitlab::Database::LoadBalancing::Sticking.stick(:runner, id)
......@@ -27,6 +29,12 @@ module EE
minutes_cost_factor(visibility_level).positive?
end
end
class_methods do
def has_shared_runners_with_non_zero_public_cost?
::Ci::Runner.instance_type.where('public_projects_minutes_cost_factor > 0').exists?
end
end
end
end
end
......@@ -93,7 +93,8 @@ module EE
has_many :sourced_pipelines, class_name: 'Ci::Sources::Project', foreign_key: :source_project_id
scope :with_shared_runners_limit_enabled, -> do
if ::Feature.enabled?(:ci_minutes_enforce_quota_for_public_projects)
if ::Feature.enabled?(:ci_minutes_enforce_quota_for_public_projects) &&
::Ci::Runner.has_shared_runners_with_non_zero_public_cost?
with_shared_runners
else
with_shared_runners.non_public_only
......
......@@ -187,6 +187,12 @@ describe Project do
end
describe '.with_shared_runners_limit_enabled' do
let(:public_cost_factor) { 1.0 }
before do
create(:ci_runner, :instance, public_projects_minutes_cost_factor: public_cost_factor)
end
it 'does not return projects without shared runners' do
project_with_shared_runners = create(:project, shared_runners_enabled: true)
project_without_shared_runners = create(:project, shared_runners_enabled: false)
......@@ -195,7 +201,7 @@ describe Project do
expect(described_class.with_shared_runners_limit_enabled).not_to include(project_without_shared_runners)
end
it 'return projects with shared runners with any visibility levels' do
it 'return projects with shared runners with positive public cost factor with any visibility levels' do
public_project_with_shared_runners = create(:project, :public, shared_runners_enabled: true)
internal_project_with_shared_runners = create(:project, :internal, shared_runners_enabled: true)
private_project_with_shared_runners = create(:project, :private, shared_runners_enabled: true)
......@@ -205,6 +211,20 @@ describe Project do
expect(described_class.with_shared_runners_limit_enabled).to include(private_project_with_shared_runners)
end
context 'and shared runners public cost factors set to 0' do
let(:public_cost_factor) { 0.0 }
it 'return projects with any visibility levels except public' do
public_project_with_shared_runners = create(:project, :public, shared_runners_enabled: true)
internal_project_with_shared_runners = create(:project, :internal, shared_runners_enabled: true)
private_project_with_shared_runners = create(:project, :private, shared_runners_enabled: true)
expect(described_class.with_shared_runners_limit_enabled).not_to include(public_project_with_shared_runners)
expect(described_class.with_shared_runners_limit_enabled).to include(internal_project_with_shared_runners)
expect(described_class.with_shared_runners_limit_enabled).to include(private_project_with_shared_runners)
end
end
context 'and :ci_minutes_enforce_quota_for_public_projects FF is disabled' do
before do
stub_feature_flags(ci_minutes_enforce_quota_for_public_projects: false)
......
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