Commit 82e244c6 authored by Fabio Pitino's avatar Fabio Pitino

Refresh CI minutes cache after updating limits

parent a24f1c03
...@@ -29,11 +29,11 @@ module EE ...@@ -29,11 +29,11 @@ module EE
::Ci::Runner.instance_type.each(&:tick_runner_queue) ::Ci::Runner.instance_type.each(&:tick_runner_queue)
end end
if params[:extra_shared_runners_minutes_limit].present? || params[:shared_runners_minutes_limit].present? namespace.update(update_attrs).tap do
if update_attrs[:extra_shared_runners_minutes_limit].present? || update_attrs[:shared_runners_minutes_limit].present?
::Ci::Minutes::RefreshCachedDataService.new(namespace).execute ::Ci::Minutes::RefreshCachedDataService.new(namespace).execute
end end
end
namespace.update(update_attrs)
end end
end end
......
...@@ -188,6 +188,10 @@ RSpec.describe API::Namespaces do ...@@ -188,6 +188,10 @@ RSpec.describe API::Namespaces do
end end
describe 'PUT /namespaces/:id' do describe 'PUT /namespaces/:id' do
let!(:namespace_statistics) do
create(:namespace_statistics, namespace: group1, shared_runners_seconds: 1600 * 60)
end
let(:params) do let(:params) do
{ {
shared_runners_minutes_limit: 9001, shared_runners_minutes_limit: 9001,
...@@ -198,9 +202,12 @@ RSpec.describe API::Namespaces do ...@@ -198,9 +202,12 @@ RSpec.describe API::Namespaces do
before do before do
allow(Gitlab).to receive(:com?).and_return(true) allow(Gitlab).to receive(:com?).and_return(true)
group1.update!(shared_runners_minutes_limit: 1000, extra_shared_runners_minutes_limit: 500)
end end
context 'when authenticated as admin' do context 'when authenticated as admin' do
subject { put api("/namespaces/#{group1.id}", admin), params: params }
it 'updates namespace using full_path when full_path contains dots' do it 'updates namespace using full_path when full_path contains dots' do
put api("/namespaces/#{group1.full_path}", admin), params: params put api("/namespaces/#{group1.full_path}", admin), params: params
...@@ -213,7 +220,7 @@ RSpec.describe API::Namespaces do ...@@ -213,7 +220,7 @@ RSpec.describe API::Namespaces do
end end
it 'updates namespace using id' do it 'updates namespace using id' do
put api("/namespaces/#{group1.id}", admin), params: params subject
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['shared_runners_minutes_limit']).to eq(params[:shared_runners_minutes_limit]) expect(json_response['shared_runners_minutes_limit']).to eq(params[:shared_runners_minutes_limit])
...@@ -224,7 +231,7 @@ RSpec.describe API::Namespaces do ...@@ -224,7 +231,7 @@ RSpec.describe API::Namespaces do
it 'expires the CI minutes CachedQuota' do it 'expires the CI minutes CachedQuota' do
expect_next(Gitlab::Ci::Minutes::CachedQuota).to receive(:expire!) expect_next(Gitlab::Ci::Minutes::CachedQuota).to receive(:expire!)
put api("/namespaces/#{group1.id}", admin), params: params subject
end end
context 'when request has extra_shared_runners_minutes_limit param' do context 'when request has extra_shared_runners_minutes_limit param' do
...@@ -233,10 +240,29 @@ RSpec.describe API::Namespaces do ...@@ -233,10 +240,29 @@ RSpec.describe API::Namespaces do
params.delete(:shared_runners_minutes_limit) params.delete(:shared_runners_minutes_limit)
end end
it 'updates the extra shared runners minutes limit' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['extra_shared_runners_minutes_limit'])
.to eq(params[:extra_shared_runners_minutes_limit])
end
it 'expires the CI minutes CachedQuota' do it 'expires the CI minutes CachedQuota' do
expect_next(Gitlab::Ci::Minutes::CachedQuota).to receive(:expire!) expect_next(Gitlab::Ci::Minutes::CachedQuota).to receive(:expire!)
put api("/namespaces/#{group1.id}", admin), params: params subject
end
it 'updates pending builds data since adding extra minutes the quota is not used up anymore' do
minutes_exceeded = group1.ci_minutes_quota.minutes_used_up?
expect(minutes_exceeded).to eq(true)
pending_build = create(:ci_pending_build, namespace: group1, minutes_exceeded: minutes_exceeded)
subject
expect(pending_build.reload.minutes_exceeded).to eq(false)
end end
end end
...@@ -245,7 +271,7 @@ RSpec.describe API::Namespaces do ...@@ -245,7 +271,7 @@ RSpec.describe API::Namespaces do
params.delete(:shared_runners_minutes_limit) params.delete(:shared_runners_minutes_limit)
expect(Gitlab::Ci::Minutes::CachedQuota).not_to receive(:new) expect(Gitlab::Ci::Minutes::CachedQuota).not_to receive(:new)
put api("/namespaces/#{group1.id}", admin), params: params subject
end 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