2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-08-25 21:42:46 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Ci::Runner do
|
2018-12-03 08:01:30 -05:00
|
|
|
it_behaves_like 'having unique enum values'
|
2018-12-03 06:10:13 -05:00
|
|
|
|
2016-05-06 03:04:09 -04:00
|
|
|
describe 'validation' do
|
2017-08-31 05:28:29 -04:00
|
|
|
it { is_expected.to validate_presence_of(:access_level) }
|
2018-05-09 03:57:16 -04:00
|
|
|
it { is_expected.to validate_presence_of(:runner_type) }
|
2017-08-31 05:28:29 -04:00
|
|
|
|
2016-05-06 03:04:09 -04:00
|
|
|
context 'when runner is not allowed to pick untagged jobs' do
|
|
|
|
context 'when runner does not have tags' do
|
|
|
|
it 'is not valid' do
|
|
|
|
runner = build(:ci_runner, tag_list: [], run_untagged: false)
|
|
|
|
expect(runner).to be_invalid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when runner has tags' do
|
|
|
|
it 'is valid' do
|
|
|
|
runner = build(:ci_runner, tag_list: ['tag'], run_untagged: false)
|
|
|
|
expect(runner).to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-12-07 11:21:16 -05:00
|
|
|
|
2018-05-23 07:23:49 -04:00
|
|
|
context '#exactly_one_group' do
|
2018-05-01 05:44:35 -04:00
|
|
|
let(:group) { create(:group) }
|
2018-05-11 06:03:40 -04:00
|
|
|
let(:runner) { create(:ci_runner, :group, groups: [group]) }
|
2018-05-01 05:44:35 -04:00
|
|
|
|
2018-05-11 06:03:40 -04:00
|
|
|
it 'disallows assigning group if already assigned to a group' do
|
2017-12-07 11:21:16 -05:00
|
|
|
runner.groups << build(:group)
|
|
|
|
|
|
|
|
expect(runner).not_to be_valid
|
2018-05-23 07:23:49 -04:00
|
|
|
expect(runner.errors.full_messages).to include('Runner needs to be assigned to exactly one group')
|
2017-12-07 11:21:16 -05:00
|
|
|
end
|
2018-05-11 06:03:40 -04:00
|
|
|
end
|
2017-12-07 11:21:16 -05:00
|
|
|
|
2018-05-11 06:03:40 -04:00
|
|
|
context 'runner_type validations' do
|
2018-05-23 07:23:49 -04:00
|
|
|
set(:group) { create(:group) }
|
|
|
|
set(:project) { create(:project) }
|
2018-05-11 06:03:40 -04:00
|
|
|
let(:group_runner) { create(:ci_runner, :group, groups: [group]) }
|
2018-05-23 07:23:49 -04:00
|
|
|
let(:project_runner) { create(:ci_runner, :project, projects: [project]) }
|
2018-05-11 06:03:40 -04:00
|
|
|
let(:instance_runner) { create(:ci_runner, :instance) }
|
2017-12-07 11:21:16 -05:00
|
|
|
|
2018-05-11 06:03:40 -04:00
|
|
|
it 'disallows assigning group to project_type runner' do
|
|
|
|
project_runner.groups << build(:group)
|
2017-12-07 11:21:16 -05:00
|
|
|
|
2018-05-11 06:03:40 -04:00
|
|
|
expect(project_runner).not_to be_valid
|
2018-05-23 07:23:49 -04:00
|
|
|
expect(project_runner.errors.full_messages).to include('Runner cannot have groups assigned')
|
2017-12-07 11:21:16 -05:00
|
|
|
end
|
|
|
|
|
2018-05-11 06:03:40 -04:00
|
|
|
it 'disallows assigning group to instance_type runner' do
|
|
|
|
instance_runner.groups << build(:group)
|
2017-12-07 11:21:16 -05:00
|
|
|
|
2018-05-11 06:03:40 -04:00
|
|
|
expect(instance_runner).not_to be_valid
|
2018-05-23 07:23:49 -04:00
|
|
|
expect(instance_runner.errors.full_messages).to include('Runner cannot have groups assigned')
|
2017-12-07 11:21:16 -05:00
|
|
|
end
|
|
|
|
|
2018-05-11 06:03:40 -04:00
|
|
|
it 'disallows assigning project to group_type runner' do
|
|
|
|
group_runner.projects << build(:project)
|
2017-12-07 11:21:16 -05:00
|
|
|
|
2018-05-11 06:03:40 -04:00
|
|
|
expect(group_runner).not_to be_valid
|
2018-05-23 07:23:49 -04:00
|
|
|
expect(group_runner.errors.full_messages).to include('Runner cannot have projects assigned')
|
2017-12-07 11:21:16 -05:00
|
|
|
end
|
|
|
|
|
2018-05-11 06:03:40 -04:00
|
|
|
it 'disallows assigning project to instance_type runner' do
|
|
|
|
instance_runner.projects << build(:project)
|
2017-12-07 11:21:16 -05:00
|
|
|
|
2018-05-11 06:03:40 -04:00
|
|
|
expect(instance_runner).not_to be_valid
|
2018-05-23 07:23:49 -04:00
|
|
|
expect(instance_runner.errors.full_messages).to include('Runner cannot have projects assigned')
|
2017-12-07 11:21:16 -05:00
|
|
|
end
|
2018-05-14 09:54:47 -04:00
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'fails to save a group assigned to a project runner even if the runner is already saved' do
|
2019-01-15 16:05:36 -05:00
|
|
|
group.runners << project_runner
|
|
|
|
expect { group.save! }
|
2018-05-14 09:54:47 -04:00
|
|
|
.to raise_error(ActiveRecord::RecordInvalid)
|
|
|
|
end
|
2017-12-07 11:21:16 -05:00
|
|
|
end
|
2016-05-06 03:04:09 -04:00
|
|
|
end
|
|
|
|
|
2017-08-31 05:28:29 -04:00
|
|
|
describe '#access_level' do
|
|
|
|
context 'when creating new runner and access_level is nil' do
|
|
|
|
let(:runner) do
|
|
|
|
build(:ci_runner, access_level: nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "object is invalid" do
|
|
|
|
expect(runner).not_to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when creating new runner and access_level is defined in enum' do
|
|
|
|
let(:runner) do
|
|
|
|
build(:ci_runner, access_level: :not_protected)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "object is valid" do
|
|
|
|
expect(runner).to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when creating new runner and access_level is not defined in enum' do
|
|
|
|
it "raises an error" do
|
|
|
|
expect { build(:ci_runner, access_level: :this_is_not_defined) }.to raise_error(ArgumentError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-26 05:36:54 -04:00
|
|
|
describe '.instance_type' do
|
2018-05-03 02:47:41 -04:00
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:project) { create(:project) }
|
2018-05-23 07:23:49 -04:00
|
|
|
let!(:group_runner) { create(:ci_runner, :group, groups: [group]) }
|
|
|
|
let!(:project_runner) { create(:ci_runner, :project, projects: [project]) }
|
2018-05-11 06:03:40 -04:00
|
|
|
let!(:shared_runner) { create(:ci_runner, :instance) }
|
2018-05-03 02:47:41 -04:00
|
|
|
|
2018-05-11 06:03:40 -04:00
|
|
|
it 'returns only shared runners' do
|
2018-06-26 05:36:54 -04:00
|
|
|
expect(described_class.instance_type).to contain_exactly(shared_runner)
|
2017-10-04 03:27:27 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.belonging_to_project' do
|
2017-09-06 05:26:55 -04:00
|
|
|
it 'returns the specific project runner' do
|
|
|
|
# own
|
2018-05-03 02:47:41 -04:00
|
|
|
specific_project = create(:project)
|
2018-05-23 07:23:49 -04:00
|
|
|
specific_runner = create(:ci_runner, :project, projects: [specific_project])
|
2017-03-01 07:07:24 -05:00
|
|
|
|
2017-09-06 05:26:55 -04:00
|
|
|
# other
|
2018-05-03 02:47:41 -04:00
|
|
|
other_project = create(:project)
|
2018-05-23 07:23:49 -04:00
|
|
|
create(:ci_runner, :project, projects: [other_project])
|
2017-03-01 07:07:24 -05:00
|
|
|
|
2017-10-04 03:27:27 -04:00
|
|
|
expect(described_class.belonging_to_project(specific_project.id)).to eq [specific_runner]
|
2017-09-06 05:26:55 -04:00
|
|
|
end
|
2017-10-04 03:27:27 -04:00
|
|
|
end
|
2017-03-01 11:19:12 -05:00
|
|
|
|
2018-04-26 21:15:54 -04:00
|
|
|
describe '.belonging_to_parent_group_of_project' do
|
2018-05-03 02:47:41 -04:00
|
|
|
let(:project) { create(:project, group: group) }
|
|
|
|
let(:group) { create(:group) }
|
2018-05-11 06:03:40 -04:00
|
|
|
let(:runner) { create(:ci_runner, :group, groups: [group]) }
|
2018-05-03 02:47:41 -04:00
|
|
|
let!(:unrelated_group) { create(:group) }
|
|
|
|
let!(:unrelated_project) { create(:project, group: unrelated_group) }
|
2018-05-11 06:03:40 -04:00
|
|
|
let!(:unrelated_runner) { create(:ci_runner, :group, groups: [unrelated_group]) }
|
2017-03-01 11:19:12 -05:00
|
|
|
|
2018-05-03 02:47:41 -04:00
|
|
|
it 'returns the specific group runner' do
|
|
|
|
expect(described_class.belonging_to_parent_group_of_project(project.id)).to contain_exactly(runner)
|
2017-09-06 05:26:55 -04:00
|
|
|
end
|
2017-10-05 14:53:24 -04:00
|
|
|
|
2018-05-03 02:47:41 -04:00
|
|
|
context 'with a parent group with a runner', :nested_groups do
|
2018-05-11 06:03:40 -04:00
|
|
|
let(:runner) { create(:ci_runner, :group, groups: [parent_group]) }
|
2018-05-03 02:47:41 -04:00
|
|
|
let(:project) { create(:project, group: group) }
|
|
|
|
let(:group) { create(:group, parent: parent_group) }
|
|
|
|
let(:parent_group) { create(:group) }
|
2017-10-05 14:53:24 -04:00
|
|
|
|
2018-05-03 02:47:41 -04:00
|
|
|
it 'returns the group runner from the parent group' do
|
|
|
|
expect(described_class.belonging_to_parent_group_of_project(project.id)).to contain_exactly(runner)
|
|
|
|
end
|
2017-10-05 14:53:24 -04:00
|
|
|
end
|
2017-10-04 03:27:27 -04:00
|
|
|
end
|
2017-03-01 11:19:12 -05:00
|
|
|
|
2018-06-26 05:36:54 -04:00
|
|
|
describe '.owned_or_instance_wide' do
|
2017-09-06 05:26:55 -04:00
|
|
|
it 'returns a globally shared, a project specific and a group specific runner' do
|
|
|
|
# group specific
|
2018-05-03 02:47:41 -04:00
|
|
|
group = create(:group)
|
|
|
|
project = create(:project, group: group)
|
2018-05-11 06:03:40 -04:00
|
|
|
group_runner = create(:ci_runner, :group, groups: [group])
|
2017-03-01 11:19:12 -05:00
|
|
|
|
2017-09-06 05:26:55 -04:00
|
|
|
# project specific
|
2018-05-11 06:03:40 -04:00
|
|
|
project_runner = create(:ci_runner, :project, projects: [project])
|
2017-09-06 05:26:55 -04:00
|
|
|
|
|
|
|
# globally shared
|
2018-05-11 06:03:40 -04:00
|
|
|
shared_runner = create(:ci_runner, :instance)
|
2017-09-06 05:26:55 -04:00
|
|
|
|
2018-06-26 05:36:54 -04:00
|
|
|
expect(described_class.owned_or_instance_wide(project.id)).to contain_exactly(
|
2017-09-06 05:26:55 -04:00
|
|
|
group_runner, project_runner, shared_runner
|
2018-05-01 05:44:35 -04:00
|
|
|
)
|
2017-03-01 07:07:24 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-25 21:42:46 -04:00
|
|
|
describe '#display_name' do
|
2016-06-16 11:33:53 -04:00
|
|
|
it 'returns the description if it has a value' do
|
2018-05-23 07:23:49 -04:00
|
|
|
runner = build(:ci_runner, description: 'Linux/Ruby-1.9.3-p448')
|
2015-08-25 21:42:46 -04:00
|
|
|
expect(runner.display_name).to eq 'Linux/Ruby-1.9.3-p448'
|
|
|
|
end
|
|
|
|
|
2016-06-16 11:33:53 -04:00
|
|
|
it 'returns the token if it does not have a description' do
|
2018-05-23 07:23:49 -04:00
|
|
|
runner = create(:ci_runner)
|
2015-08-25 21:42:46 -04:00
|
|
|
expect(runner.display_name).to eq runner.description
|
|
|
|
end
|
|
|
|
|
2016-06-16 11:33:53 -04:00
|
|
|
it 'returns the token if the description is an empty string' do
|
2018-05-23 07:23:49 -04:00
|
|
|
runner = build(:ci_runner, description: '', token: 'token')
|
2015-08-25 21:42:46 -04:00
|
|
|
expect(runner.display_name).to eq runner.token
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-08 02:46:41 -04:00
|
|
|
describe '#assign_to' do
|
2018-05-23 07:23:49 -04:00
|
|
|
let(:project) { create(:project) }
|
2015-08-25 21:42:46 -04:00
|
|
|
|
2018-05-10 06:40:30 -04:00
|
|
|
subject { runner.assign_to(project) }
|
|
|
|
|
|
|
|
context 'with shared_runner' do
|
2018-05-23 07:23:49 -04:00
|
|
|
let(:runner) { create(:ci_runner, :instance) }
|
2018-05-10 06:40:30 -04:00
|
|
|
|
|
|
|
it 'transitions shared runner to project runner and assigns project' do
|
2018-05-28 06:49:08 -04:00
|
|
|
expect(subject).to be_truthy
|
2018-05-23 07:23:49 -04:00
|
|
|
|
2018-05-10 06:40:30 -04:00
|
|
|
expect(runner).to be_project_type
|
|
|
|
expect(runner.projects).to eq([project])
|
|
|
|
expect(runner.only_for?(project)).to be_truthy
|
|
|
|
end
|
2016-06-02 11:28:14 -04:00
|
|
|
end
|
2015-08-25 21:42:46 -04:00
|
|
|
|
2018-05-10 06:40:30 -04:00
|
|
|
context 'with group runner' do
|
2018-05-23 07:23:49 -04:00
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:runner) { create(:ci_runner, :group, groups: [group]) }
|
2018-05-10 06:40:30 -04:00
|
|
|
|
|
|
|
it 'raises an error' do
|
|
|
|
expect { subject }
|
|
|
|
.to raise_error(ArgumentError, 'Transitioning a group runner to a project runner is not supported')
|
|
|
|
end
|
|
|
|
end
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
|
2016-06-08 02:46:41 -04:00
|
|
|
describe '.online' do
|
2017-07-25 13:09:00 -04:00
|
|
|
subject { described_class.online }
|
2015-10-12 15:12:31 -04:00
|
|
|
|
|
|
|
before do
|
2018-06-06 09:29:40 -04:00
|
|
|
@runner1 = create(:ci_runner, :instance, contacted_at: 1.hour.ago)
|
2018-05-23 07:23:49 -04:00
|
|
|
@runner2 = create(:ci_runner, :instance, contacted_at: 1.second.ago)
|
2015-10-12 15:12:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq([@runner2])}
|
|
|
|
end
|
|
|
|
|
2016-06-08 02:46:41 -04:00
|
|
|
describe '#online?' do
|
2018-05-23 07:23:49 -04:00
|
|
|
let(:runner) { create(:ci_runner, :instance) }
|
2015-10-12 15:12:31 -04:00
|
|
|
|
|
|
|
subject { runner.online? }
|
|
|
|
|
2018-02-05 10:47:04 -05:00
|
|
|
before do
|
|
|
|
allow_any_instance_of(described_class).to receive(:cached_attribute).and_call_original
|
|
|
|
allow_any_instance_of(described_class).to receive(:cached_attribute)
|
|
|
|
.with(:platform).and_return("darwin")
|
|
|
|
end
|
|
|
|
|
2018-01-28 18:25:13 -05:00
|
|
|
context 'no cache value' do
|
2016-06-02 11:28:14 -04:00
|
|
|
before do
|
2018-01-29 14:56:28 -05:00
|
|
|
stub_redis_runner_contacted_at(nil)
|
2016-06-02 11:28:14 -04:00
|
|
|
end
|
2015-10-12 15:12:31 -04:00
|
|
|
|
2018-01-28 18:25:13 -05:00
|
|
|
context 'never contacted' do
|
|
|
|
before do
|
|
|
|
runner.contacted_at = nil
|
|
|
|
end
|
2015-10-12 15:12:31 -04:00
|
|
|
|
2018-01-28 18:25:13 -05:00
|
|
|
it { is_expected.to be_falsey }
|
2016-06-02 11:28:14 -04:00
|
|
|
end
|
2015-10-12 15:12:31 -04:00
|
|
|
|
2018-01-28 18:25:13 -05:00
|
|
|
context 'contacted long time ago time' do
|
|
|
|
before do
|
|
|
|
runner.contacted_at = 1.year.ago
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'contacted 1s ago' do
|
|
|
|
before do
|
|
|
|
runner.contacted_at = 1.second.ago
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
2015-10-12 15:12:31 -04:00
|
|
|
end
|
|
|
|
|
2018-01-28 18:25:13 -05:00
|
|
|
context 'with cache value' do
|
|
|
|
context 'contacted long time ago time' do
|
|
|
|
before do
|
2018-01-29 17:00:39 -05:00
|
|
|
runner.contacted_at = 1.year.ago
|
2018-01-29 14:56:28 -05:00
|
|
|
stub_redis_runner_contacted_at(1.year.ago.to_s)
|
2018-01-28 18:25:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
2016-06-02 11:28:14 -04:00
|
|
|
end
|
2015-10-12 15:12:31 -04:00
|
|
|
|
2018-01-28 18:25:13 -05:00
|
|
|
context 'contacted 1s ago' do
|
|
|
|
before do
|
2018-01-29 17:00:39 -05:00
|
|
|
runner.contacted_at = 50.minutes.ago
|
2018-01-29 14:56:28 -05:00
|
|
|
stub_redis_runner_contacted_at(1.second.ago.to_s)
|
2018-01-28 18:25:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-29 14:56:28 -05:00
|
|
|
def stub_redis_runner_contacted_at(value)
|
2018-02-04 12:34:21 -05:00
|
|
|
Gitlab::Redis::SharedState.with do |redis|
|
2018-02-05 10:47:04 -05:00
|
|
|
cache_key = runner.send(:cache_attribute_key)
|
|
|
|
expect(redis).to receive(:get).with(cache_key)
|
|
|
|
.and_return({ contacted_at: value }.to_json).at_least(:once)
|
2018-02-04 12:34:21 -05:00
|
|
|
end
|
2015-10-12 15:12:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-06 09:29:40 -04:00
|
|
|
describe '.offline' do
|
|
|
|
subject { described_class.offline }
|
|
|
|
|
|
|
|
before do
|
|
|
|
@runner1 = create(:ci_runner, :instance, contacted_at: 1.hour.ago)
|
|
|
|
@runner2 = create(:ci_runner, :instance, contacted_at: 1.second.ago)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq([@runner1])}
|
|
|
|
end
|
|
|
|
|
2016-06-08 03:19:49 -04:00
|
|
|
describe '#can_pick?' do
|
2018-05-23 07:23:49 -04:00
|
|
|
set(:pipeline) { create(:ci_pipeline) }
|
2016-06-15 05:34:44 -04:00
|
|
|
let(:build) { create(:ci_build, pipeline: pipeline) }
|
2018-05-23 07:23:49 -04:00
|
|
|
let(:runner_project) { build.project }
|
|
|
|
let(:runner) { create(:ci_runner, :project, projects: [runner_project], tag_list: tag_list, run_untagged: run_untagged) }
|
2018-05-03 03:38:19 -04:00
|
|
|
let(:tag_list) { [] }
|
|
|
|
let(:run_untagged) { true }
|
2016-06-08 03:19:49 -04:00
|
|
|
|
2017-08-28 08:10:01 -04:00
|
|
|
subject { runner.can_pick?(build) }
|
|
|
|
|
2017-10-04 11:11:53 -04:00
|
|
|
context 'a different runner' do
|
2018-05-23 07:23:49 -04:00
|
|
|
let(:other_project) { create(:project) }
|
|
|
|
let(:other_runner) { create(:ci_runner, :project, projects: [other_project], tag_list: tag_list, run_untagged: run_untagged) }
|
2018-05-28 09:32:31 -04:00
|
|
|
|
2017-10-04 11:11:53 -04:00
|
|
|
it 'cannot handle builds' do
|
|
|
|
expect(other_runner.can_pick?(build)).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-08 03:19:49 -04:00
|
|
|
context 'when runner does not have tags' do
|
|
|
|
it 'can handle builds without tags' do
|
|
|
|
expect(runner.can_pick?(build)).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'cannot handle build with tags' do
|
|
|
|
build.tag_list = ['aa']
|
2016-06-16 11:26:49 -04:00
|
|
|
|
2016-06-08 03:19:49 -04:00
|
|
|
expect(runner.can_pick?(build)).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when runner has tags' do
|
2018-05-03 03:38:19 -04:00
|
|
|
let(:tag_list) { %w(bb cc) }
|
2016-06-08 03:19:49 -04:00
|
|
|
|
|
|
|
shared_examples 'tagged build picker' do
|
|
|
|
it 'can handle build with matching tags' do
|
|
|
|
build.tag_list = ['bb']
|
2016-06-16 11:26:49 -04:00
|
|
|
|
2016-06-08 03:19:49 -04:00
|
|
|
expect(runner.can_pick?(build)).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'cannot handle build without matching tags' do
|
|
|
|
build.tag_list = ['aa']
|
2016-06-16 11:26:49 -04:00
|
|
|
|
2016-06-08 03:19:49 -04:00
|
|
|
expect(runner.can_pick?(build)).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when runner can pick untagged jobs' do
|
|
|
|
it 'can handle builds without tags' do
|
|
|
|
expect(runner.can_pick?(build)).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'tagged build picker'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when runner cannot pick untagged jobs' do
|
2018-05-03 03:38:19 -04:00
|
|
|
let(:run_untagged) { false }
|
2016-06-08 03:19:49 -04:00
|
|
|
|
|
|
|
it 'cannot handle builds without tags' do
|
|
|
|
expect(runner.can_pick?(build)).to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'tagged build picker'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-25 10:23:13 -04:00
|
|
|
context 'when runner is shared' do
|
2018-05-23 07:23:49 -04:00
|
|
|
let(:runner) { create(:ci_runner, :instance) }
|
2016-06-08 03:19:49 -04:00
|
|
|
|
2017-09-25 10:23:13 -04:00
|
|
|
it 'can handle builds' do
|
|
|
|
expect(runner.can_pick?(build)).to be_truthy
|
|
|
|
end
|
2016-06-08 03:19:49 -04:00
|
|
|
|
2017-09-25 10:23:13 -04:00
|
|
|
context 'when runner is locked' do
|
2018-05-23 07:23:49 -04:00
|
|
|
let(:runner) { create(:ci_runner, :instance, locked: true) }
|
2016-06-08 03:19:49 -04:00
|
|
|
|
2017-09-25 10:23:13 -04:00
|
|
|
it 'can handle builds' do
|
|
|
|
expect(runner.can_pick?(build)).to be_truthy
|
2016-06-08 03:19:49 -04:00
|
|
|
end
|
|
|
|
end
|
2017-09-25 10:23:13 -04:00
|
|
|
end
|
2016-06-08 03:19:49 -04:00
|
|
|
|
2017-09-25 10:23:13 -04:00
|
|
|
context 'when runner is not shared' do
|
|
|
|
context 'when runner is assigned to a project' do
|
|
|
|
it 'can handle builds' do
|
2016-06-08 03:19:49 -04:00
|
|
|
expect(runner.can_pick?(build)).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-23 07:23:49 -04:00
|
|
|
context 'when runner is assigned to another project' do
|
|
|
|
let(:runner_project) { create(:project) }
|
2016-06-08 03:19:49 -04:00
|
|
|
|
2017-09-25 10:23:13 -04:00
|
|
|
it 'cannot handle builds' do
|
2016-06-08 03:19:49 -04:00
|
|
|
expect(runner.can_pick?(build)).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
2017-10-04 11:11:53 -04:00
|
|
|
|
|
|
|
context 'when runner is assigned to a group' do
|
2018-05-23 07:23:49 -04:00
|
|
|
let(:group) { create(:group, projects: [build.project]) }
|
|
|
|
let(:runner) { create(:ci_runner, :group, tag_list: tag_list, run_untagged: run_untagged, groups: [group]) }
|
2017-10-04 11:11:53 -04:00
|
|
|
|
|
|
|
it 'can handle builds' do
|
|
|
|
expect(runner.can_pick?(build)).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
2016-06-08 03:19:49 -04:00
|
|
|
end
|
2017-08-28 08:10:01 -04:00
|
|
|
|
2017-09-02 03:31:14 -04:00
|
|
|
context 'when access_level of runner is not_protected' do
|
|
|
|
before do
|
|
|
|
runner.not_protected!
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when build is protected' do
|
|
|
|
before do
|
|
|
|
build.protected = true
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when build is unprotected' do
|
|
|
|
before do
|
|
|
|
build.protected = false
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when access_level of runner is ref_protected' do
|
2017-08-28 08:10:01 -04:00
|
|
|
before do
|
2017-08-29 02:56:03 -04:00
|
|
|
runner.ref_protected!
|
2017-08-28 08:10:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when build is protected' do
|
|
|
|
before do
|
|
|
|
build.protected = true
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when build is unprotected' do
|
|
|
|
before do
|
|
|
|
build.protected = false
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
end
|
2016-06-08 03:19:49 -04:00
|
|
|
end
|
|
|
|
|
2016-06-08 02:46:41 -04:00
|
|
|
describe '#status' do
|
2018-05-23 07:23:49 -04:00
|
|
|
let(:runner) { create(:ci_runner, :instance, contacted_at: 1.second.ago) }
|
2015-10-12 15:12:31 -04:00
|
|
|
|
|
|
|
subject { runner.status }
|
|
|
|
|
|
|
|
context 'never connected' do
|
2016-06-02 11:28:14 -04:00
|
|
|
before do
|
|
|
|
runner.contacted_at = nil
|
|
|
|
end
|
2015-10-12 15:12:31 -04:00
|
|
|
|
|
|
|
it { is_expected.to eq(:not_connected) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'contacted 1s ago' do
|
2016-06-02 11:28:14 -04:00
|
|
|
before do
|
|
|
|
runner.contacted_at = 1.second.ago
|
|
|
|
end
|
2015-10-12 15:12:31 -04:00
|
|
|
|
|
|
|
it { is_expected.to eq(:online) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'contacted long time ago' do
|
2016-06-02 11:28:14 -04:00
|
|
|
before do
|
|
|
|
runner.contacted_at = 1.year.ago
|
|
|
|
end
|
2015-10-12 15:12:31 -04:00
|
|
|
|
|
|
|
it { is_expected.to eq(:offline) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'inactive' do
|
2016-06-02 11:28:14 -04:00
|
|
|
before do
|
|
|
|
runner.active = false
|
|
|
|
end
|
2015-10-12 15:12:31 -04:00
|
|
|
|
|
|
|
it { is_expected.to eq(:paused) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-04 04:46:56 -05:00
|
|
|
describe '#tick_runner_queue' do
|
|
|
|
let(:runner) { create(:ci_runner) }
|
|
|
|
|
|
|
|
it 'returns a new last_update value' do
|
|
|
|
expect(runner.tick_runner_queue).not_to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#ensure_runner_queue_value' do
|
|
|
|
let(:runner) { create(:ci_runner) }
|
|
|
|
|
|
|
|
it 'sets a new last_update value when it is called the first time' do
|
|
|
|
last_update = runner.ensure_runner_queue_value
|
|
|
|
|
2017-07-10 23:35:47 -04:00
|
|
|
expect_value_in_queues.to eq(last_update)
|
2017-01-04 04:46:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not change if it is not expired and called again' do
|
|
|
|
last_update = runner.ensure_runner_queue_value
|
|
|
|
|
|
|
|
expect(runner.ensure_runner_queue_value).to eq(last_update)
|
2017-07-10 23:35:47 -04:00
|
|
|
expect_value_in_queues.to eq(last_update)
|
2017-01-04 04:46:56 -05:00
|
|
|
end
|
|
|
|
|
2017-01-19 17:31:03 -05:00
|
|
|
context 'updates runner queue after changing editable value' do
|
|
|
|
let!(:last_update) { runner.ensure_runner_queue_value }
|
|
|
|
|
|
|
|
before do
|
2017-01-20 08:57:01 -05:00
|
|
|
Ci::UpdateRunnerService.new(runner).update(description: 'new runner')
|
2017-01-19 17:31:03 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets a new last_update value' do
|
2017-07-10 23:35:47 -04:00
|
|
|
expect_value_in_queues.not_to eq(last_update)
|
2017-01-19 17:31:03 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'does not update runner value after save' do
|
|
|
|
let!(:last_update) { runner.ensure_runner_queue_value }
|
|
|
|
|
|
|
|
before do
|
|
|
|
runner.touch
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has an old last_update value' do
|
2017-07-10 23:35:47 -04:00
|
|
|
expect_value_in_queues.to eq(last_update)
|
2017-01-19 17:31:03 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-10 23:35:47 -04:00
|
|
|
def expect_value_in_queues
|
2019-07-22 02:00:37 -04:00
|
|
|
Gitlab::Redis::SharedState.with do |redis|
|
2017-01-04 04:46:56 -05:00
|
|
|
runner_queue_key = runner.send(:runner_queue_key)
|
2017-01-19 17:31:03 -05:00
|
|
|
expect(redis.get(runner_queue_key))
|
2017-01-04 04:46:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-04 12:34:21 -05:00
|
|
|
describe '#update_cached_info' do
|
2018-05-28 12:17:18 -04:00
|
|
|
let(:runner) { create(:ci_runner, :project) }
|
2018-01-29 14:56:28 -05:00
|
|
|
|
2018-02-04 12:34:21 -05:00
|
|
|
subject { runner.update_cached_info(architecture: '18-bit') }
|
2018-01-29 14:56:28 -05:00
|
|
|
|
|
|
|
context 'when database was updated recently' do
|
|
|
|
before do
|
2018-01-29 17:27:03 -05:00
|
|
|
runner.contacted_at = Time.now
|
2018-01-29 14:56:28 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates cache' do
|
2018-02-05 10:47:04 -05:00
|
|
|
expect_redis_update
|
2018-01-29 14:56:28 -05:00
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when database was not updated recently' do
|
|
|
|
before do
|
2018-01-29 17:27:03 -05:00
|
|
|
runner.contacted_at = 2.hours.ago
|
2018-01-29 14:56:28 -05:00
|
|
|
end
|
|
|
|
|
2018-05-28 12:17:18 -04:00
|
|
|
context 'with invalid runner' do
|
|
|
|
before do
|
|
|
|
runner.projects = []
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'still updates redis cache and database' do
|
|
|
|
expect(runner).to be_invalid
|
2018-01-29 14:56:28 -05:00
|
|
|
|
2018-05-28 12:17:18 -04:00
|
|
|
expect_redis_update
|
|
|
|
does_db_update
|
|
|
|
end
|
2018-01-29 14:56:28 -05:00
|
|
|
end
|
|
|
|
|
2018-05-28 12:17:18 -04:00
|
|
|
it 'updates redis cache and database' do
|
2018-02-05 10:47:04 -05:00
|
|
|
expect_redis_update
|
2018-05-28 12:17:18 -04:00
|
|
|
does_db_update
|
2018-01-29 14:56:28 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-05 10:47:04 -05:00
|
|
|
def expect_redis_update
|
2018-02-04 12:34:21 -05:00
|
|
|
Gitlab::Redis::SharedState.with do |redis|
|
2018-02-05 10:47:04 -05:00
|
|
|
redis_key = runner.send(:cache_attribute_key)
|
|
|
|
expect(redis).to receive(:set).with(redis_key, anything, any_args)
|
2018-01-29 15:53:37 -05:00
|
|
|
end
|
2018-01-29 14:56:28 -05:00
|
|
|
end
|
2018-05-28 12:17:18 -04:00
|
|
|
|
|
|
|
def does_db_update
|
|
|
|
expect { subject }.to change { runner.reload.read_attribute(:contacted_at) }
|
|
|
|
.and change { runner.reload.read_attribute(:architecture) }
|
|
|
|
end
|
2018-01-29 14:56:28 -05:00
|
|
|
end
|
|
|
|
|
2017-01-20 13:38:58 -05:00
|
|
|
describe '#destroy' do
|
|
|
|
let(:runner) { create(:ci_runner) }
|
|
|
|
|
|
|
|
context 'when there is a tick in the queue' do
|
|
|
|
let!(:queue_key) { runner.send(:runner_queue_key) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
runner.tick_runner_queue
|
|
|
|
runner.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'cleans up the queue' do
|
2019-07-22 02:00:37 -04:00
|
|
|
Gitlab::Redis::SharedState.with do |redis|
|
2017-01-20 13:38:58 -05:00
|
|
|
expect(redis.get(queue_key)).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-20 04:52:05 -04:00
|
|
|
describe '.assignable_for' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2018-05-24 06:43:48 -04:00
|
|
|
let(:group) { create(:group) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:another_project) { create(:project) }
|
2018-05-24 06:43:48 -04:00
|
|
|
let!(:unlocked_project_runner) { create(:ci_runner, :project, projects: [project]) }
|
|
|
|
let!(:locked_project_runner) { create(:ci_runner, :project, locked: true, projects: [project]) }
|
|
|
|
let!(:group_runner) { create(:ci_runner, :group, groups: [group]) }
|
|
|
|
let!(:instance_runner) { create(:ci_runner, :instance) }
|
2016-06-02 06:41:26 -04:00
|
|
|
|
2018-05-24 06:43:48 -04:00
|
|
|
context 'with already assigned project' do
|
|
|
|
subject { described_class.assignable_for(project) }
|
2016-06-02 06:41:26 -04:00
|
|
|
|
2018-05-09 08:46:34 -04:00
|
|
|
it { is_expected.to be_empty }
|
2016-06-02 06:41:26 -04:00
|
|
|
end
|
|
|
|
|
2018-05-09 08:46:34 -04:00
|
|
|
context 'with a different project' do
|
|
|
|
subject { described_class.assignable_for(another_project) }
|
2016-06-02 06:41:26 -04:00
|
|
|
|
2018-05-09 08:46:34 -04:00
|
|
|
it { is_expected.to include(unlocked_project_runner) }
|
|
|
|
it { is_expected.not_to include(group_runner) }
|
|
|
|
it { is_expected.not_to include(locked_project_runner) }
|
|
|
|
it { is_expected.not_to include(instance_runner) }
|
2016-06-02 06:41:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-25 21:42:46 -04:00
|
|
|
describe "belongs_to_one_project?" do
|
|
|
|
it "returns false if there are two projects runner assigned to" do
|
2018-05-23 07:23:49 -04:00
|
|
|
project1 = create(:project)
|
|
|
|
project2 = create(:project)
|
|
|
|
runner = create(:ci_runner, :project, projects: [project1, project2])
|
2015-08-25 21:42:46 -04:00
|
|
|
|
2015-09-10 09:52:52 -04:00
|
|
|
expect(runner.belongs_to_one_project?).to be_falsey
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true" do
|
2018-05-23 07:23:49 -04:00
|
|
|
project = create(:project)
|
|
|
|
runner = create(:ci_runner, :project, projects: [project])
|
2015-08-25 21:42:46 -04:00
|
|
|
|
2015-09-10 09:52:52 -04:00
|
|
|
expect(runner.belongs_to_one_project?).to be_truthy
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
end
|
2016-03-01 10:41:18 -05:00
|
|
|
|
2016-05-06 03:04:09 -04:00
|
|
|
describe '#has_tags?' do
|
|
|
|
context 'when runner has tags' do
|
|
|
|
subject { create(:ci_runner, tag_list: ['tag']) }
|
|
|
|
it { is_expected.to have_tags }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when runner does not have tags' do
|
|
|
|
subject { create(:ci_runner, tag_list: []) }
|
2016-05-23 19:37:59 -04:00
|
|
|
it { is_expected.not_to have_tags }
|
2016-05-06 03:04:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.search' do
|
2017-11-24 06:24:24 -05:00
|
|
|
let(:runner) { create(:ci_runner, token: '123abc', description: 'test runner') }
|
2016-03-01 10:41:18 -05:00
|
|
|
|
|
|
|
it 'returns runners with a matching token' do
|
|
|
|
expect(described_class.search(runner.token)).to eq([runner])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns runners with a partially matching token' do
|
|
|
|
expect(described_class.search(runner.token[0..2])).to eq([runner])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns runners with a matching token regardless of the casing' do
|
|
|
|
expect(described_class.search(runner.token.upcase)).to eq([runner])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns runners with a matching description' do
|
|
|
|
expect(described_class.search(runner.description)).to eq([runner])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns runners with a partially matching description' do
|
|
|
|
expect(described_class.search(runner.description[0..2])).to eq([runner])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns runners with a matching description regardless of the casing' do
|
|
|
|
expect(described_class.search(runner.description.upcase)).to eq([runner])
|
|
|
|
end
|
|
|
|
end
|
2017-09-25 09:28:33 -04:00
|
|
|
|
2018-05-03 03:38:19 -04:00
|
|
|
describe '#assigned_to_group?' do
|
|
|
|
subject { runner.assigned_to_group? }
|
|
|
|
|
|
|
|
context 'when project runner' do
|
2018-05-23 07:23:49 -04:00
|
|
|
let(:runner) { create(:ci_runner, :project, description: 'Project runner', projects: [project]) }
|
2018-05-03 03:38:19 -04:00
|
|
|
let(:project) { create(:project) }
|
2017-09-25 09:28:33 -04:00
|
|
|
|
2018-05-03 03:38:19 -04:00
|
|
|
it { is_expected.to be_falsey }
|
2017-09-25 09:28:33 -04:00
|
|
|
end
|
|
|
|
|
2018-05-03 03:38:19 -04:00
|
|
|
context 'when shared runner' do
|
2018-05-23 07:23:49 -04:00
|
|
|
let(:runner) { create(:ci_runner, :instance, description: 'Shared runner') }
|
2017-09-25 09:28:33 -04:00
|
|
|
|
2018-05-03 03:38:19 -04:00
|
|
|
it { is_expected.to be_falsey }
|
2017-09-25 09:28:33 -04:00
|
|
|
end
|
|
|
|
|
2018-05-03 03:38:19 -04:00
|
|
|
context 'when group runner' do
|
|
|
|
let(:group) { create(:group) }
|
2018-05-11 06:03:40 -04:00
|
|
|
let(:runner) { create(:ci_runner, :group, description: 'Group runner', groups: [group]) }
|
2017-09-25 09:28:33 -04:00
|
|
|
|
2018-05-03 03:38:19 -04:00
|
|
|
it { is_expected.to be_truthy }
|
2017-09-25 09:28:33 -04:00
|
|
|
end
|
|
|
|
end
|
2017-10-04 07:55:34 -04:00
|
|
|
|
2018-05-03 03:38:19 -04:00
|
|
|
describe '#assigned_to_project?' do
|
|
|
|
subject { runner.assigned_to_project? }
|
2017-10-04 07:55:34 -04:00
|
|
|
|
2018-05-03 03:38:19 -04:00
|
|
|
context 'when group runner' do
|
2018-05-11 06:03:40 -04:00
|
|
|
let(:runner) { create(:ci_runner, :group, description: 'Group runner', groups: [group]) }
|
2018-05-03 03:38:19 -04:00
|
|
|
let(:group) { create(:group) }
|
|
|
|
it { is_expected.to be_falsey }
|
2017-10-04 07:55:34 -04:00
|
|
|
end
|
|
|
|
|
2018-05-03 03:38:19 -04:00
|
|
|
context 'when shared runner' do
|
2018-05-11 06:03:40 -04:00
|
|
|
let(:runner) { create(:ci_runner, :instance, description: 'Shared runner') }
|
2018-05-03 03:38:19 -04:00
|
|
|
it { is_expected.to be_falsey }
|
2017-10-04 07:55:34 -04:00
|
|
|
end
|
|
|
|
|
2018-05-03 03:38:19 -04:00
|
|
|
context 'when project runner' do
|
2018-05-23 07:23:49 -04:00
|
|
|
let(:runner) { create(:ci_runner, :project, description: 'Project runner', projects: [project]) }
|
2018-05-03 03:38:19 -04:00
|
|
|
let(:project) { create(:project) }
|
2017-10-04 07:55:34 -04:00
|
|
|
|
2018-05-03 03:38:19 -04:00
|
|
|
it { is_expected.to be_truthy }
|
2017-10-04 07:55:34 -04:00
|
|
|
end
|
|
|
|
end
|
2017-12-19 09:12:21 -05:00
|
|
|
|
2018-05-02 10:42:12 -04:00
|
|
|
describe '#pick_build!' do
|
2018-02-26 10:20:29 -05:00
|
|
|
context 'runner can pick the build' do
|
|
|
|
it 'calls #tick_runner_queue' do
|
2018-05-03 03:38:19 -04:00
|
|
|
ci_build = build(:ci_build)
|
|
|
|
runner = build(:ci_runner)
|
2018-02-26 10:20:29 -05:00
|
|
|
allow(runner).to receive(:can_pick?).with(ci_build).and_return(true)
|
|
|
|
|
|
|
|
expect(runner).to receive(:tick_runner_queue)
|
|
|
|
|
2018-05-02 10:42:12 -04:00
|
|
|
runner.pick_build!(ci_build)
|
2018-02-26 10:20:29 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'runner cannot pick the build' do
|
|
|
|
it 'does not call #tick_runner_queue' do
|
2018-05-03 03:38:19 -04:00
|
|
|
ci_build = build(:ci_build)
|
|
|
|
runner = build(:ci_runner)
|
2018-02-26 10:20:29 -05:00
|
|
|
allow(runner).to receive(:can_pick?).with(ci_build).and_return(false)
|
|
|
|
|
|
|
|
expect(runner).not_to receive(:tick_runner_queue)
|
|
|
|
|
2018-05-02 10:42:12 -04:00
|
|
|
runner.pick_build!(ci_build)
|
2018-02-26 10:20:29 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-05-28 07:44:37 -04:00
|
|
|
|
|
|
|
describe 'project runner without projects is destroyable' do
|
2018-05-28 11:58:46 -04:00
|
|
|
subject { create(:ci_runner, :project, :without_projects) }
|
2018-05-28 07:44:37 -04:00
|
|
|
|
|
|
|
it 'does not have projects' do
|
|
|
|
expect(subject.runner_projects).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can be destroyed' do
|
2018-05-30 09:43:30 -04:00
|
|
|
subject
|
2018-05-28 11:14:15 -04:00
|
|
|
expect { subject.destroy }.to change { described_class.count }.by(-1)
|
2018-05-28 07:44:37 -04:00
|
|
|
end
|
|
|
|
end
|
2018-09-14 09:05:46 -04:00
|
|
|
|
|
|
|
describe '.order_by' do
|
|
|
|
it 'supports ordering by the contact date' do
|
|
|
|
runner1 = create(:ci_runner, contacted_at: 1.year.ago)
|
|
|
|
runner2 = create(:ci_runner, contacted_at: 1.month.ago)
|
|
|
|
runners = described_class.order_by('contacted_asc')
|
|
|
|
|
|
|
|
expect(runners).to eq([runner1, runner2])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'supports ordering by the creation date' do
|
|
|
|
runner1 = create(:ci_runner, created_at: 1.year.ago)
|
|
|
|
runner2 = create(:ci_runner, created_at: 1.month.ago)
|
|
|
|
runners = described_class.order_by('created_asc')
|
|
|
|
|
|
|
|
expect(runners).to eq([runner2, runner1])
|
|
|
|
end
|
|
|
|
end
|
2019-01-04 00:54:45 -05:00
|
|
|
|
|
|
|
describe '#uncached_contacted_at' do
|
|
|
|
let(:contacted_at_stored) { 1.hour.ago.change(usec: 0) }
|
|
|
|
let(:runner) { create(:ci_runner, contacted_at: contacted_at_stored) }
|
|
|
|
|
|
|
|
subject { runner.uncached_contacted_at }
|
|
|
|
|
|
|
|
it { is_expected.to eq(contacted_at_stored) }
|
|
|
|
end
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|