Fix locked shared runners problem

This commit is contained in:
Tomasz Maczukin 2017-09-25 16:23:13 +02:00
parent 8b1a3d40e7
commit 48d9a72291
No known key found for this signature in database
GPG Key ID: 7E9EB2E4B0F625CD
2 changed files with 21 additions and 54 deletions

View File

@ -174,7 +174,7 @@ module Ci
end
def assignable_for?(project)
!locked? || projects.exists?(id: project.id)
is_shared? || projects.exists?(id: project.id)
end
def accepting_tags?(build)

View File

@ -183,75 +183,42 @@ describe Ci::Runner do
end
end
context 'when runner is locked' do
context 'when runner is shared' do
before do
runner.locked = true
runner.is_shared = true
build.project.runners = []
end
shared_examples 'locked build picker' do
context 'when runner cannot pick untagged jobs' do
before do
runner.run_untagged = false
end
it 'cannot handle builds without tags' do
expect(runner.can_pick?(build)).to be_falsey
end
end
context 'when having runner tags' do
before do
runner.tag_list = %w(bb cc)
end
it 'cannot handle it for builds without matching tags' do
build.tag_list = ['aa']
expect(runner.can_pick?(build)).to be_falsey
end
end
it 'can handle builds' do
expect(runner.can_pick?(build)).to be_truthy
end
context 'when serving the same project' do
it 'can handle it' do
context 'when runner is locked' do
before do
runner.locked = true
end
it 'can handle builds' do
expect(runner.can_pick?(build)).to be_truthy
end
end
end
it_behaves_like 'locked build picker'
context 'when having runner tags' do
before do
runner.tag_list = %w(bb cc)
build.tag_list = ['bb']
end
it 'can handle it for matching tags' do
expect(runner.can_pick?(build)).to be_truthy
end
context 'when runner is not shared' do
context 'when runner is assigned to a project' do
it 'can handle builds' do
expect(runner.can_pick?(build)).to be_truthy
end
end
context 'serving a different project' do
context 'when runner is not assigned to a project' do
before do
runner.runner_projects.destroy_all
build.project.runners = []
end
it 'cannot handle it' do
it 'cannot handle builds' do
expect(runner.can_pick?(build)).to be_falsey
end
it_behaves_like 'locked build picker'
context 'when having runner tags' do
before do
runner.tag_list = %w(bb cc)
build.tag_list = ['bb']
end
it 'cannot handle it for matching tags' do
expect(runner.can_pick?(build)).to be_falsey
end
end
end
end