Commit 02f7d42a authored by Nick Thomas's avatar Nick Thomas

Merge branch '326989_use_cache_for_runners_states' into 'master'

Remove feature flag for "runners_cached_states" [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!61998
parents ef58aa70 1ebf1606
......@@ -753,22 +753,14 @@ module Ci
end
def any_runners_online?
if Feature.enabled?(:runners_cached_states, project, default_enabled: :yaml)
cache_for_online_runners do
project.any_online_runners? { |runner| runner.match_build_if_online?(self) }
end
else
project.any_active_runners? { |runner| runner.match_build_if_online?(self) }
cache_for_online_runners do
project.any_online_runners? { |runner| runner.match_build_if_online?(self) }
end
end
def any_runners_available?
if Feature.enabled?(:runners_cached_states, project, default_enabled: :yaml)
cache_for_available_runners do
project.active_runners.exists?
end
else
project.any_active_runners?
cache_for_available_runners do
project.active_runners.exists?
end
end
......
......@@ -1751,11 +1751,6 @@ class Project < ApplicationRecord
end
end
# Deprecated: https://gitlab.com/gitlab-org/gitlab/-/issues/326989
def any_active_runners?(&block)
active_runners_with_tags.any?(&block)
end
def any_online_runners?(&block)
online_runners_with_tags.any?(&block)
end
......
---
title: Use cache for CI::Build runners check
merge_request: 61998
author:
type: performance
---
name: runners_cached_states
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/57367
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/326989
milestone: '13.11'
type: development
group: group::source code
default_enabled: false
......@@ -1087,25 +1087,6 @@ RSpec.describe Project do
end
end
describe '#any_active_runners?' do
let!(:shared_runner) { create(:ci_runner, :instance) }
it { expect(project.any_active_runners?).to be_truthy }
context 'with used pipeline minutes' do
let(:namespace) { create(:namespace, :with_used_build_minutes_limit) }
let(:project) do
create(:project,
namespace: namespace,
shared_runners_enabled: true)
end
it 'does not have any active runners' do
expect(project.any_active_runners?).to be_falsey
end
end
end
describe '#any_online_runners?' do
let!(:shared_runner) { create(:ci_runner, :instance, :online) }
......
......@@ -662,28 +662,10 @@ RSpec.describe Ci::Build do
end
end
context 'with runners_cached_states feature flag enabled' do
before do
stub_feature_flags(runners_cached_states: true)
end
it 'caches the result in Redis' do
expect(Rails.cache).to receive(:fetch).with(['has-online-runners', build.id], expires_in: 1.minute)
build.any_runners_online?
end
end
it 'caches the result in Redis' do
expect(Rails.cache).to receive(:fetch).with(['has-online-runners', build.id], expires_in: 1.minute)
context 'with runners_cached_states feature flag disabled' do
before do
stub_feature_flags(runners_cached_states: false)
end
it 'does not cache' do
expect(Rails.cache).not_to receive(:fetch).with(['has-online-runners', build.id], expires_in: 1.minute)
build.any_runners_online?
end
build.any_runners_online?
end
end
......@@ -700,28 +682,10 @@ RSpec.describe Ci::Build do
it { is_expected.to be_truthy }
end
context 'with runners_cached_states feature flag enabled' do
before do
stub_feature_flags(runners_cached_states: true)
end
it 'caches the result in Redis' do
expect(Rails.cache).to receive(:fetch).with(['has-available-runners', build.project.id], expires_in: 1.minute)
build.any_runners_available?
end
end
it 'caches the result in Redis' do
expect(Rails.cache).to receive(:fetch).with(['has-available-runners', build.project.id], expires_in: 1.minute)
context 'with runners_cached_states feature flag disabled' do
before do
stub_feature_flags(runners_cached_states: false)
end
it 'does not cache' do
expect(Rails.cache).not_to receive(:fetch).with(['has-available-runners', build.project.id], expires_in: 1.minute)
build.any_runners_available?
end
build.any_runners_available?
end
end
......
......@@ -1632,112 +1632,6 @@ RSpec.describe Project, factory_default: :keep do
end
end
describe '#any_active_runners?' do
subject { project.any_active_runners? }
context 'shared runners' do
let(:project) { create(:project, shared_runners_enabled: shared_runners_enabled) }
let(:specific_runner) { create(:ci_runner, :project, projects: [project]) }
let(:shared_runner) { create(:ci_runner, :instance) }
context 'for shared runners disabled' do
let(:shared_runners_enabled) { false }
it 'has no runners available' do
is_expected.to be_falsey
end
it 'has a specific runner' do
specific_runner
is_expected.to be_truthy
end
it 'has a shared runner, but they are prohibited to use' do
shared_runner
is_expected.to be_falsey
end
it 'checks the presence of specific runner' do
specific_runner
expect(project.any_active_runners? { |runner| runner == specific_runner }).to be_truthy
end
it 'returns false if match cannot be found' do
specific_runner
expect(project.any_active_runners? { false }).to be_falsey
end
end
context 'for shared runners enabled' do
let(:shared_runners_enabled) { true }
it 'has a shared runner' do
shared_runner
is_expected.to be_truthy
end
it 'checks the presence of shared runner' do
shared_runner
expect(project.any_active_runners? { |runner| runner == shared_runner }).to be_truthy
end
it 'returns false if match cannot be found' do
shared_runner
expect(project.any_active_runners? { false }).to be_falsey
end
end
end
context 'group runners' do
let(:project) { create(:project, group_runners_enabled: group_runners_enabled) }
let(:group) { create(:group, projects: [project]) }
let(:group_runner) { create(:ci_runner, :group, groups: [group]) }
context 'for group runners disabled' do
let(:group_runners_enabled) { false }
it 'has no runners available' do
is_expected.to be_falsey
end
it 'has a group runner, but they are prohibited to use' do
group_runner
is_expected.to be_falsey
end
end
context 'for group runners enabled' do
let(:group_runners_enabled) { true }
it 'has a group runner' do
group_runner
is_expected.to be_truthy
end
it 'checks the presence of group runner' do
group_runner
expect(project.any_active_runners? { |runner| runner == group_runner }).to be_truthy
end
it 'returns false if match cannot be found' do
group_runner
expect(project.any_active_runners? { false }).to be_falsey
end
end
end
end
describe '#any_online_runners?' do
subject { project.any_online_runners? }
......
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