debian-mirror-gitlab/spec/models/ci/runner_manager_build_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

101 lines
3.5 KiB
Ruby
Raw Normal View History

2023-05-27 22:25:52 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-06-20 00:43:36 +05:30
RSpec.describe Ci::RunnerManagerBuild, model: true, feature_category: :runner_fleet do
2023-05-27 22:25:52 +05:30
let_it_be(:runner) { create(:ci_runner) }
2023-06-20 00:43:36 +05:30
let_it_be(:runner_manager) { create(:ci_runner_machine, runner: runner) }
let_it_be(:build) { create(:ci_build, runner_manager: runner_manager) }
2023-05-27 22:25:52 +05:30
it { is_expected.to belong_to(:build) }
2023-06-20 00:43:36 +05:30
it { is_expected.to belong_to(:runner_manager) }
2023-05-27 22:25:52 +05:30
describe 'partitioning' do
context 'with build' do
let(:build) { FactoryBot.build(:ci_build, partition_id: ci_testing_partition_id) }
2023-06-20 00:43:36 +05:30
let(:runner_manager_build) { FactoryBot.build(:ci_runner_machine_build, build: build) }
2023-05-27 22:25:52 +05:30
it 'sets partition_id to the current partition value' do
2023-06-20 00:43:36 +05:30
expect { runner_manager_build.valid? }.to change { runner_manager_build.partition_id }
2023-05-27 22:25:52 +05:30
.to(ci_testing_partition_id)
end
context 'when it is already set' do
2023-06-20 00:43:36 +05:30
let(:runner_manager_build) { FactoryBot.build(:ci_runner_machine_build, partition_id: 125) }
2023-05-27 22:25:52 +05:30
it 'does not change the partition_id value' do
2023-06-20 00:43:36 +05:30
expect { runner_manager_build.valid? }.not_to change { runner_manager_build.partition_id }
2023-05-27 22:25:52 +05:30
end
end
end
context 'without build' do
2023-06-20 00:43:36 +05:30
let(:runner_manager_build) { FactoryBot.build(:ci_runner_machine_build, build: nil) }
2023-05-27 22:25:52 +05:30
it { is_expected.to validate_presence_of(:partition_id) }
it 'does not change the partition_id value' do
2023-06-20 00:43:36 +05:30
expect { runner_manager_build.valid? }.not_to change { runner_manager_build.partition_id }
2023-05-27 22:25:52 +05:30
end
end
end
describe 'ci_sliding_list partitioning' do
let(:connection) { described_class.connection }
let(:partition_manager) { Gitlab::Database::Partitioning::PartitionManager.new(described_class) }
let(:partitioning_strategy) { described_class.partitioning_strategy }
it { expect(partitioning_strategy.missing_partitions).to be_empty }
it { expect(partitioning_strategy.extra_partitions).to be_empty }
it { expect(partitioning_strategy.current_partitions).to include partitioning_strategy.initial_partition }
it { expect(partitioning_strategy.active_partition).to be_present }
end
2023-06-20 00:43:36 +05:30
context 'loose foreign key on p_ci_runner_manager_builds.runner_manager_id' do # rubocop:disable RSpec/ContextWording
2023-05-27 22:25:52 +05:30
it_behaves_like 'cleanup by a loose foreign key' do
let!(:parent) { create(:ci_runner_machine) }
2023-06-20 00:43:36 +05:30
let!(:model) { create(:ci_runner_machine_build, runner_manager: parent) }
2023-05-27 22:25:52 +05:30
end
end
describe '.for_build' do
subject(:for_build) { described_class.for_build(build_id) }
context 'with valid build_id' do
let(:build_id) { build.id }
it { is_expected.to contain_exactly(described_class.find_by_build_id(build_id)) }
end
context 'with valid build_ids' do
2023-06-20 00:43:36 +05:30
let(:build2) { create(:ci_build, runner_manager: runner_manager) }
2023-05-27 22:25:52 +05:30
let(:build_id) { [build, build2] }
it { is_expected.to eq(described_class.where(build_id: build_id)) }
end
context 'with non-existeng build_id' do
let(:build_id) { non_existing_record_id }
it { is_expected.to be_empty }
end
end
2023-06-20 00:43:36 +05:30
describe '.pluck_runner_manager_id_and_build_id' do
subject { scope.pluck_build_id_and_runner_manager_id }
2023-05-27 22:25:52 +05:30
context 'with default scope' do
let(:scope) { described_class }
2023-06-20 00:43:36 +05:30
it { is_expected.to eq({ build.id => runner_manager.id }) }
2023-05-27 22:25:52 +05:30
end
context 'with scope excluding build' do
let(:scope) { described_class.where(build_id: non_existing_record_id) }
it { is_expected.to be_empty }
end
end
end