Commit 7a3f47a0 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch 'selective-merge-train-concurrency' into 'master'

Selective merge train concurrency via feature flag

See merge request gitlab-org/gitlab!19131
parents 594c3ea3 d007e3ff
......@@ -4,8 +4,10 @@ module MergeTrains
include ::Gitlab::ExclusiveLeaseHelpers
include ::Gitlab::Utils::StrongMemoize
DEFAULT_MAX_CONCURRENCY = 4
ONE_AT_A_TIME_STRATEGY = 1
HIGH_CONCURRENCY = 20
MEDIUM_CONCURRENCY = 10
LOW_CONCURRENCY = 4
NO_CONCURRENCY = 1
##
# merge_request ... A merge request pointer in a merge train.
......@@ -68,9 +70,15 @@ module MergeTrains
def max_concurrency
strong_memoize(:max_concurrency) do
if Feature.enabled?(:merge_trains_parallel_pipelines, project, default_enabled: true)
DEFAULT_MAX_CONCURRENCY
if Feature.enabled?(:merge_trains_high_concurrency, project)
HIGH_CONCURRENCY
elsif Feature.enabled?(:merge_trains_medium_concurrency, project)
MEDIUM_CONCURRENCY
else
ONE_AT_A_TIME_STRATEGY
LOW_CONCURRENCY
end
else
NO_CONCURRENCY
end
end
end
......
......@@ -180,4 +180,60 @@ describe MergeTrains::RefreshMergeRequestsService do
end
end
end
describe '#max_concurrency' do
subject { service.send(:max_concurrency) }
context 'when `merge_trains_parallel_pipelines` feature flag is enabled' do
before do
stub_feature_flags(merge_trains_parallel_pipelines: true)
end
context 'when `merge_trains_high_concurrency` feature flag is enabled' do
before do
stub_feature_flags(merge_trains_high_concurrency: true)
end
it 'returns high concurrency' do
is_expected.to eq(described_class::HIGH_CONCURRENCY)
end
end
context 'when `merge_trains_high_concurrency` feature flag is disabled' do
before do
stub_feature_flags(merge_trains_high_concurrency: false)
end
context 'when `merge_trains_medium_concurrency` feature flag is enabled' do
before do
stub_feature_flags(merge_trains_medium_concurrency: true)
end
it 'returns medium concurrency' do
is_expected.to eq(described_class::MEDIUM_CONCURRENCY)
end
end
context 'when `merge_trains_medium_concurrency` feature flag is disabled' do
before do
stub_feature_flags(merge_trains_medium_concurrency: false)
end
it 'returns low concurrency' do
is_expected.to eq(described_class::LOW_CONCURRENCY)
end
end
end
end
context 'when `merge_trains_parallel_pipelines` feature flag is disabled' do
before do
stub_feature_flags(merge_trains_parallel_pipelines: false)
end
it 'returns no concurrency' do
is_expected.to eq(described_class::NO_CONCURRENCY)
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