Commit 271267ed authored by Avielle Wolfe's avatar Avielle Wolfe

Track build minutes for disabled shared runners

We still want to track minutes when shared runners have been disabled on
a project in order to prevent a hack by which a user is able to enqueue
a pipeline and disable shared runners in order to use shared runners
without it counting towards the usage quota.

Changelog: fixed
EE: true
parent 7c37d8c5
......@@ -71,7 +71,7 @@ module Ci
def namespace_eligible?
strong_memoize(:namespace_eligible) do
namespace.root? && namespace.any_project_with_shared_runners_enabled?
namespace.root?
end
end
......
......@@ -68,7 +68,7 @@ module EE
end
def shared_runners_minutes_limit_enabled?
project.shared_runners_minutes_limit_enabled? && runner&.cost_factor_enabled?(project)
runner&.cost_factor_enabled?(project)
end
def log_geo_deleted_event
......
......@@ -51,29 +51,12 @@ RSpec.describe Ci::Build do
describe '#shared_runners_minutes_limit_enabled?' do
subject { job.shared_runners_minutes_limit_enabled? }
shared_examples 'depends on runner presence and type' do
context 'for shared runner' do
before do
job.runner = create(:ci_runner, :instance)
end
context 'when project#shared_runners_minutes_limit_enabled? is true' do
specify do
expect(job.project).to receive(:shared_runners_minutes_limit_enabled?)
.and_return(true)
is_expected.to be_truthy
end
end
context 'when project#shared_runners_minutes_limit_enabled? is false' do
specify do
expect(job.project).to receive(:shared_runners_minutes_limit_enabled?)
.and_return(false)
is_expected.to be_falsey
end
end
it { is_expected.to be_truthy }
end
context 'with specific runner' do
......@@ -89,9 +72,6 @@ RSpec.describe Ci::Build do
end
end
it_behaves_like 'depends on runner presence and type'
end
context 'updates pipeline minutes' do
let(:job) { create(:ci_build, :running, pipeline: pipeline) }
......
......@@ -38,13 +38,13 @@ RSpec.describe Ci::Minutes::Quota do
end
end
context 'when namespace does not have projects with shared runners enabled' do
context 'when namespace has a limit but does not have projects with shared runners enabled' do
before do
project.update!(shared_runners_enabled: false)
allow(namespace).to receive(:shared_runners_minutes_limit).and_return(1000)
end
it { is_expected.to be_falsey }
it { is_expected.to be_truthy }
end
end
......@@ -422,26 +422,10 @@ RSpec.describe Ci::Minutes::Quota do
end
context 'when namespace is root' do
before do
create(:project, namespace: namespace, shared_runners_enabled: shared_runners_enabled)
end
context 'and it has a project without any shared runner enabled' do
let(:shared_runners_enabled) { false }
it 'is false' do
expect(subject).to be_falsey
end
end
context 'and it has a project with shared runner enabled' do
let(:shared_runners_enabled) { true }
it 'is true' do
expect(subject).to be_truthy
end
end
end
it 'does not trigger N+1 queries when called multiple times' do
# memoizes the result
......
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