Commit d61a96fb authored by Rubén Dávila's avatar Rubén Dávila

Fix calculation of used extra CI minutes

When a Group/Personal namespace is using the Free plan on GL.com then
the assigned CI minutes is read from
`Gitlab::CurrentSettings.shared_runners_minutes` and not from
`Namespace#shared_runners_minutes`.

In the previous version we were using
`Namespace#shared_runners_minutes_limit` which was returning `nil`
instead of 2000 (The current default CI minutes configured globally for
free plans in GL.com). This bug was affecting Pipelines and was showing
wrong information on the Pipeline Quote info for the Group/Personal
namespace.

Now we're using `Namespace#actual_shared_runners_minutes_limit` which
returns the globally configured value if the current Namespace has not
been configured with CI minutes.
parent 527cca19
......@@ -12,7 +12,7 @@ class NamespaceStatistics < ApplicationRecord
end
def extra_shared_runners_minutes
limit = namespace.shared_runners_minutes_limit.to_i
limit = namespace.actual_shared_runners_minutes_limit(include_extra: false)
extra_limit = namespace.extra_shared_runners_minutes_limit.to_i
return 0 if extra_limit.zero? || shared_runners_minutes <= limit
......
---
title: Fix calculation of used extra CI minutes
merge_request: 14217
author:
type: fixed
......@@ -46,5 +46,49 @@ describe NamespaceStatistics do
it { is_expected.to eq(0) }
end
context 'when limit is defined globally' do
before do
namespace.update_attribute(:shared_runners_minutes_limit, nil)
stub_application_setting(shared_runners_minutes: 100)
end
context 'when usage is above the main quota' do
before do
namespace_statistics.update_attribute(:shared_runners_seconds, 101 * 60)
end
context 'and extra CI minutes have been assigned' do
before do
namespace.update_attribute(:extra_shared_runners_minutes_limit, 50)
end
it { is_expected.to eq(1) }
end
context 'and extra CI minutes have not been assigned' do
before do
namespace.update_attribute(:extra_shared_runners_minutes_limit, nil)
end
it { is_expected.to eq(0) }
end
end
context 'when usage is below the main quota' do
before do
namespace_statistics.update_attribute(:shared_runners_seconds, 90 * 60)
end
context 'and extra CI minutes have been assigned' do
before do
namespace.update_attribute(:extra_shared_runners_minutes_limit, 50)
end
it { is_expected.to eq(0) }
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