Commit 8b3f6e31 authored by James Lopez's avatar James Lopez

Merge branch 'rd-fix-calculation-of-extra-minutes-used-for-free-plans' into 'master'

Fix calculation of used extra CI minutes

See merge request gitlab-org/gitlab-ee!14217
parents de578b8f d61a96fb
......@@ -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