Commit 83df6384 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Disallow runner to pick untagged build if configured

parent 2aa57071
...@@ -290,6 +290,10 @@ module Ci ...@@ -290,6 +290,10 @@ module Ci
end end
def can_be_served?(runner) def can_be_served?(runner)
if tag_list.empty? && !runner.run_untagged?
return false
end
(tag_list - runner.tag_list).empty? (tag_list - runner.tag_list).empty?
end end
......
...@@ -259,11 +259,11 @@ describe Ci::Build, models: true do ...@@ -259,11 +259,11 @@ describe Ci::Build, models: true do
end end
describe '#can_be_served?' do describe '#can_be_served?' do
let(:runner) { FactoryGirl.create :ci_runner } let(:runner) { create(:ci_runner) }
before { build.project.runners << runner } before { build.project.runners << runner }
context 'runner without tags' do context 'when runner does not have tags' do
it 'can handle builds without tags' do it 'can handle builds without tags' do
expect(build.can_be_served?(runner)).to be_truthy expect(build.can_be_served?(runner)).to be_truthy
end end
...@@ -274,23 +274,39 @@ describe Ci::Build, models: true do ...@@ -274,23 +274,39 @@ describe Ci::Build, models: true do
end end
end end
context 'runner with tags' do context 'when runner has tags' do
before { runner.tag_list = ['bb', 'cc'] } before { runner.tag_list = ['bb', 'cc'] }
it 'can handle builds without tags' do shared_examples 'tagged build picker' do
expect(build.can_be_served?(runner)).to be_truthy
end
it 'can handle build with matching tags' do it 'can handle build with matching tags' do
build.tag_list = ['bb'] build.tag_list = ['bb']
expect(build.can_be_served?(runner)).to be_truthy expect(build.can_be_served?(runner)).to be_truthy
end end
it 'cannot handle build with not matching tags' do it 'cannot handle build without matching tags' do
build.tag_list = ['aa'] build.tag_list = ['aa']
expect(build.can_be_served?(runner)).to be_falsey expect(build.can_be_served?(runner)).to be_falsey
end end
end end
context 'when runner can pick untagged jobs' do
it 'can handle builds without tags' do
expect(build.can_be_served?(runner)).to be_truthy
end
it_behaves_like 'tagged build picker'
end
context 'when runner can not pick untagged jobs' do
before { runner.run_untagged = false }
it 'can not handle builds without tags' do
expect(build.can_be_served?(runner)).to be_falsey
end
it_behaves_like 'tagged build picker'
end
end
end end
describe '#any_runners_online?' do describe '#any_runners_online?' do
......
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