Commit d0a17a9f authored by Aleksei Lipniagov's avatar Aleksei Lipniagov

Update :with_shared_runners_limit_enabled scope

Do not include public project into :with_shared_runners_limit_enabled
scope if `public_projects_minutes_cost_factor` of shared runners set to
0.
parent a2cd8492
...@@ -27,6 +27,14 @@ module EE ...@@ -27,6 +27,14 @@ module EE
minutes_cost_factor(visibility_level).positive? minutes_cost_factor(visibility_level).positive?
end end
end end
class << self
def has_shared_runners_with_non_zero_public_cost?
Rails.cache.fetch(:shared_runners_public_cost_factor, expires_in: 1.day) do
::Ci::Runner.instance_type.where('public_projects_minutes_cost_factor > 0').exists?
end
end
end
end end
end end
end end
...@@ -93,7 +93,8 @@ module EE ...@@ -93,7 +93,8 @@ module EE
has_many :sourced_pipelines, class_name: 'Ci::Sources::Project', foreign_key: :source_project_id has_many :sourced_pipelines, class_name: 'Ci::Sources::Project', foreign_key: :source_project_id
scope :with_shared_runners_limit_enabled, -> do 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) &&
::EE::Ci::Runner.has_shared_runners_with_non_zero_public_cost?
with_shared_runners with_shared_runners
else else
with_shared_runners.non_public_only with_shared_runners.non_public_only
......
...@@ -187,6 +187,12 @@ describe Project do ...@@ -187,6 +187,12 @@ describe Project do
end end
describe '.with_shared_runners_limit_enabled' do 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 it 'does not return projects without shared runners' do
project_with_shared_runners = create(:project, shared_runners_enabled: true) project_with_shared_runners = create(:project, shared_runners_enabled: true)
project_without_shared_runners = create(:project, shared_runners_enabled: false) project_without_shared_runners = create(:project, shared_runners_enabled: false)
...@@ -195,7 +201,7 @@ describe Project do ...@@ -195,7 +201,7 @@ describe Project do
expect(described_class.with_shared_runners_limit_enabled).not_to include(project_without_shared_runners) expect(described_class.with_shared_runners_limit_enabled).not_to include(project_without_shared_runners)
end 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) public_project_with_shared_runners = create(:project, :public, shared_runners_enabled: true)
internal_project_with_shared_runners = create(:project, :internal, 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) private_project_with_shared_runners = create(:project, :private, shared_runners_enabled: true)
...@@ -205,6 +211,20 @@ describe Project do ...@@ -205,6 +211,20 @@ describe Project do
expect(described_class.with_shared_runners_limit_enabled).to include(private_project_with_shared_runners) expect(described_class.with_shared_runners_limit_enabled).to include(private_project_with_shared_runners)
end 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 context 'and :ci_minutes_enforce_quota_for_public_projects FF is disabled' do
before do before do
stub_feature_flags(ci_minutes_enforce_quota_for_public_projects: false) 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