debian-mirror-gitlab/spec/services/ci/update_build_queue_service_spec.rb

101 lines
2.8 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Ci::UpdateBuildQueueService do
2017-08-17 22:00:37 +05:30
let(:project) { create(:project, :repository) }
let(:build) { create(:ci_build, pipeline: pipeline) }
let(:pipeline) { create(:ci_pipeline, project: project) }
2019-12-04 20:38:33 +05:30
shared_examples 'refreshes runner' do
it 'ticks runner queue value' do
expect { subject.execute(build) }.to change { runner.ensure_runner_queue_value }
2017-08-17 22:00:37 +05:30
end
2019-12-04 20:38:33 +05:30
end
2017-08-17 22:00:37 +05:30
2019-12-04 20:38:33 +05:30
shared_examples 'does not refresh runner' do
it 'ticks runner queue value' do
expect { subject.execute(build) }.not_to change { runner.ensure_runner_queue_value }
2017-08-17 22:00:37 +05:30
end
end
2019-12-04 20:38:33 +05:30
shared_examples 'matching build' do
context 'when there is a online runner that can pick build' do
before do
runner.update!(contacted_at: 30.minutes.ago)
2017-08-17 22:00:37 +05:30
end
2019-12-04 20:38:33 +05:30
it_behaves_like 'refreshes runner'
2017-08-17 22:00:37 +05:30
end
2019-12-04 20:38:33 +05:30
end
2017-08-17 22:00:37 +05:30
2019-12-04 20:38:33 +05:30
shared_examples 'mismatching tags' do
2018-10-15 14:42:47 +05:30
context 'when there is no runner that can pick build due to tag mismatch' do
2017-09-10 17:25:29 +05:30
before do
build.tag_list = [:docker]
end
2017-08-17 22:00:37 +05:30
2019-12-04 20:38:33 +05:30
it_behaves_like 'does not refresh runner'
2018-10-15 14:42:47 +05:30
end
2019-12-04 20:38:33 +05:30
end
2018-10-15 14:42:47 +05:30
2019-12-04 20:38:33 +05:30
shared_examples 'recent runner queue' do
context 'when there is runner with expired cache' do
2018-10-15 14:42:47 +05:30
before do
2019-12-04 20:38:33 +05:30
runner.update!(contacted_at: Ci::Runner.recent_queue_deadline)
2018-10-15 14:42:47 +05:30
end
2021-01-03 14:25:43 +05:30
it_behaves_like 'does not refresh runner'
2018-10-15 14:42:47 +05:30
end
end
2019-12-04 20:38:33 +05:30
context 'when updating specific runners' do
let(:runner) { create(:ci_runner, :project, projects: [project]) }
2018-10-15 14:42:47 +05:30
2019-12-04 20:38:33 +05:30
it_behaves_like 'matching build'
it_behaves_like 'mismatching tags'
it_behaves_like 'recent runner queue'
context 'when the runner is assigned to another project' do
let(:another_project) { create(:project) }
let(:runner) { create(:ci_runner, :project, projects: [another_project]) }
it_behaves_like 'does not refresh runner'
2018-10-15 14:42:47 +05:30
end
2019-12-04 20:38:33 +05:30
end
2018-10-15 14:42:47 +05:30
2019-12-04 20:38:33 +05:30
context 'when updating shared runners' do
let(:runner) { create(:ci_runner, :instance) }
it_behaves_like 'matching build'
it_behaves_like 'mismatching tags'
it_behaves_like 'recent runner queue'
context 'when there is no runner that can pick build due to being disabled on project' do
2018-10-15 14:42:47 +05:30
before do
2019-12-04 20:38:33 +05:30
build.project.shared_runners_enabled = false
2018-10-15 14:42:47 +05:30
end
2019-12-04 20:38:33 +05:30
it_behaves_like 'does not refresh runner'
2018-10-15 14:42:47 +05:30
end
2019-12-04 20:38:33 +05:30
end
context 'when updating group runners' do
let(:group) { create(:group) }
let(:project) { create(:project, group: group) }
let(:runner) { create(:ci_runner, :group, groups: [group]) }
it_behaves_like 'matching build'
it_behaves_like 'mismatching tags'
it_behaves_like 'recent runner queue'
2018-10-15 14:42:47 +05:30
context 'when there is no runner that can pick build due to being disabled on project' do
before do
build.project.group_runners_enabled = false
end
2019-12-04 20:38:33 +05:30
it_behaves_like 'does not refresh runner'
2017-08-17 22:00:37 +05:30
end
end
end