diff options
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/ci/build_spec.rb | 22 | ||||
-rw-r--r-- | spec/models/ci/job_artifact_spec.rb | 78 | ||||
-rw-r--r-- | spec/models/ci/runner_spec.rb | 40 | ||||
-rw-r--r-- | spec/models/commit_status_spec.rb | 22 | ||||
-rw-r--r-- | spec/models/concerns/ci/partitionable/switch_spec.rb | 20 | ||||
-rw-r--r-- | spec/models/concerns/ci/partitionable_spec.rb | 10 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 18 |
7 files changed, 119 insertions, 91 deletions
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 54c0c086144..90edbf530cf 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -5566,4 +5566,26 @@ RSpec.describe Ci::Build, feature_category: :continuous_integration, factory_def end end end + + describe 'routing table switch' do + context 'with ff disabled' do + before do + stub_feature_flags(ci_partitioning_use_ci_builds_routing_table: false) + end + + it 'uses the legacy table' do + expect(described_class.table_name).to eq('ci_builds') + end + end + + context 'with ff enabled' do + before do + stub_feature_flags(ci_partitioning_use_ci_builds_routing_table: true) + end + + it 'uses the routing table' do + expect(described_class.table_name).to eq('p_ci_builds') + end + end + end end diff --git a/spec/models/ci/job_artifact_spec.rb b/spec/models/ci/job_artifact_spec.rb index 498af80dbb6..83c233fa942 100644 --- a/spec/models/ci/job_artifact_spec.rb +++ b/spec/models/ci/job_artifact_spec.rb @@ -824,82 +824,4 @@ RSpec.describe Ci::JobArtifact, feature_category: :build_artifacts do it { is_expected.to eq(artifact.file.filename) } end - - describe '#to_deleted_object_attrs' do - let(:pick_up_at) { nil } - let(:expire_at) { nil } - let(:file_final_path) { nil } - - let(:artifact) do - create( - :ci_job_artifact, - :archive, - :remote_store, - file_final_path: file_final_path, - expire_at: expire_at - ) - end - - subject(:attributes) { artifact.to_deleted_object_attrs(pick_up_at) } - - before do - stub_artifacts_object_storage - end - - shared_examples_for 'returning attributes for object deletion' do - it 'returns the file store' do - expect(attributes[:file_store]).to eq(artifact.file_store) - end - - context 'when pick_up_at is present' do - let(:pick_up_at) { 2.hours.ago } - - it 'returns the pick_up_at value' do - expect(attributes[:pick_up_at]).to eq(pick_up_at) - end - end - - context 'when pick_up_at is not present' do - context 'and expire_at is present' do - let(:expire_at) { 4.hours.ago } - - it 'sets expire_at as pick_up_at' do - expect(attributes[:pick_up_at]).to eq(expire_at) - end - end - - context 'and expire_at is not present' do - it 'sets current time as pick_up_at' do - freeze_time do - expect(attributes[:pick_up_at]).to eq(Time.current) - end - end - end - end - end - - context 'when file_final_path is present' do - let(:file_final_path) { 'some/hash/path/to/randomfile' } - - it 'returns the store_dir and file based on the file_final_path' do - expect(attributes).to include( - store_dir: 'some/hash/path/to', - file: 'randomfile' - ) - end - - it_behaves_like 'returning attributes for object deletion' - end - - context 'when file_final_path is not present' do - it 'returns the uploader default store_dir and file_identifier' do - expect(attributes).to include( - store_dir: artifact.file.store_dir.to_s, - file: artifact.file_identifier - ) - end - - it_behaves_like 'returning attributes for object deletion' - end - end end diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb index 50e2ded695c..56e69cc2b9c 100644 --- a/spec/models/ci/runner_spec.rb +++ b/spec/models/ci/runner_spec.rb @@ -1968,19 +1968,29 @@ RSpec.describe Ci::Runner, type: :model, feature_category: :runner do end describe '.with_upgrade_status' do - subject { described_class.with_upgrade_status(upgrade_status) } + subject(:scope) { described_class.with_upgrade_status(upgrade_status) } - let_it_be(:runner_14_0_0) { create(:ci_runner, version: '14.0.0') } - let_it_be(:runner_14_1_0) { create(:ci_runner, version: '14.1.0') } - let_it_be(:runner_14_1_1) { create(:ci_runner, version: '14.1.1') } - let_it_be(:runner_version_14_0_0) { create(:ci_runner_version, version: '14.0.0', status: :available) } - let_it_be(:runner_version_14_1_0) { create(:ci_runner_version, version: '14.1.0', status: :recommended) } - let_it_be(:runner_version_14_1_1) { create(:ci_runner_version, version: '14.1.1', status: :unavailable) } + let_it_be(:runner_14_0_0) { create(:ci_runner) } + let_it_be(:runner_14_1_0_and_14_0_0) { create(:ci_runner) } + let_it_be(:runner_14_1_0) { create(:ci_runner) } + let_it_be(:runner_14_1_1) { create(:ci_runner) } + + before_all do + create(:ci_runner_machine, runner: runner_14_1_0_and_14_0_0, version: '14.0.0') + create(:ci_runner_machine, runner: runner_14_1_0_and_14_0_0, version: '14.1.0') + create(:ci_runner_machine, runner: runner_14_0_0, version: '14.0.0') + create(:ci_runner_machine, runner: runner_14_1_0, version: '14.1.0') + create(:ci_runner_machine, runner: runner_14_1_1, version: '14.1.1') + + create(:ci_runner_version, version: '14.0.0', status: :available) + create(:ci_runner_version, version: '14.1.0', status: :recommended) + create(:ci_runner_version, version: '14.1.1', status: :unavailable) + end context ':unavailable' do let(:upgrade_status) { :unavailable } - it 'returns runners whose version is assigned :unavailable' do + it 'returns runners with runner managers whose version is assigned :unavailable' do is_expected.to contain_exactly(runner_14_1_1) end end @@ -1988,23 +1998,27 @@ RSpec.describe Ci::Runner, type: :model, feature_category: :runner do context ':available' do let(:upgrade_status) { :available } - it 'returns runners whose version is assigned :available' do - is_expected.to contain_exactly(runner_14_0_0) + it 'returns runners with runner managers whose version is assigned :available' do + is_expected.to contain_exactly(runner_14_0_0, runner_14_1_0_and_14_0_0) end end context ':recommended' do let(:upgrade_status) { :recommended } - it 'returns runners whose version is assigned :recommended' do - is_expected.to contain_exactly(runner_14_1_0) + it 'returns runners with runner managers whose version is assigned :recommended' do + is_expected.to contain_exactly(runner_14_1_0_and_14_0_0, runner_14_1_0) end end describe 'composed with other scopes' do subject { described_class.active(false).with_upgrade_status(:available) } - let(:inactive_runner_14_0_0) { create(:ci_runner, version: '14.0.0', active: false) } + before do + create(:ci_runner_machine, runner: inactive_runner_14_0_0, version: '14.0.0') + end + + let(:inactive_runner_14_0_0) { create(:ci_runner, active: false) } it 'returns runner matching the composed scope' do is_expected.to contain_exactly(inactive_runner_14_0_0) diff --git a/spec/models/commit_status_spec.rb b/spec/models/commit_status_spec.rb index ac356bcd65a..9ce9f0e13b5 100644 --- a/spec/models/commit_status_spec.rb +++ b/spec/models/commit_status_spec.rb @@ -1067,4 +1067,26 @@ RSpec.describe CommitStatus, feature_category: :continuous_integration do it_behaves_like 'having enum with nil value' end + + describe 'routing table switch' do + context 'with ff disabled' do + before do + stub_feature_flags(ci_partitioning_use_ci_builds_routing_table: false) + end + + it 'uses the legacy table' do + expect(described_class.table_name).to eq('ci_builds') + end + end + + context 'with ff enabled' do + before do + stub_feature_flags(ci_partitioning_use_ci_builds_routing_table: true) + end + + it 'uses the routing table' do + expect(described_class.table_name).to eq('p_ci_builds') + end + end + end end diff --git a/spec/models/concerns/ci/partitionable/switch_spec.rb b/spec/models/concerns/ci/partitionable/switch_spec.rb index 551ae111fa4..4aaf69bb585 100644 --- a/spec/models/concerns/ci/partitionable/switch_spec.rb +++ b/spec/models/concerns/ci/partitionable/switch_spec.rb @@ -38,6 +38,7 @@ RSpec.describe Ci::Partitionable::Switch, :aggregate_failures do id serial NOT NULL PRIMARY KEY, job_id int, partition_id int NOT NULL DEFAULT 1, + type text, expanded_environment_name text); CREATE TABLE _test_p_ci_jobs_metadata ( @@ -89,6 +90,25 @@ RSpec.describe Ci::Partitionable::Switch, :aggregate_failures do it { expect(partitioned_model.sequence_name).to eq('_test_ci_jobs_metadata_id_seq') } + context 'with singe table inheritance' do + let(:child_model) do + Class.new(model) do + def self.name + 'TestSwitchJobMetadataChild' + end + end + end + + it 'adds a Partitioned model for each descendant' do + expect(model::Partitioned).not_to eq(child_model::Partitioned) + end + + it 'uses the parent name in STI queries' do + recorder = ActiveRecord::QueryRecorder.new { child_model.all.load } + expect(recorder.log).to include(/"type" = 'TestSwitchJobMetadataChild'/) + end + end + context 'when switching the tables' do before do stub_feature_flags(table_rollout_flag => false) diff --git a/spec/models/concerns/ci/partitionable_spec.rb b/spec/models/concerns/ci/partitionable_spec.rb index d41654e547e..6daafc78cff 100644 --- a/spec/models/concerns/ci/partitionable_spec.rb +++ b/spec/models/concerns/ci/partitionable_spec.rb @@ -25,7 +25,11 @@ RSpec.describe Ci::Partitionable do end context 'with through options' do + let(:disable_partitionable_switch) { nil } + before do + stub_env('DISABLE_PARTITIONABLE_SWITCH', disable_partitionable_switch) + allow(ActiveSupport::DescendantsTracker).to receive(:store_inherited) stub_const("#{described_class}::Testing::PARTITIONABLE_MODELS", [ci_model.name]) @@ -39,6 +43,12 @@ RSpec.describe Ci::Partitionable do it { expect(ci_model.routing_table_name_flag).to eq(:some_flag) } it { expect(ci_model.ancestors).to include(described_class::Switch) } + + context 'when DISABLE_PARTITIONABLE_SWITCH is set' do + let(:disable_partitionable_switch) { true } + + it { expect(ci_model.ancestors).not_to include(described_class::Switch) } + end end context 'with partitioned options' do diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 9f9417c2483..72c966f8ca5 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -3804,4 +3804,22 @@ RSpec.describe Repository, feature_category: :source_code_management do include_examples 'does not delete branch' end end + + describe '#get_patch_id' do + it 'returns patch_id of given revisions' do + expect(repository.get_patch_id('HEAD~', 'HEAD')).to eq('45435e5d7b339dd76d939508c7687701d0c17fff') + end + + context 'when one of the param is invalid' do + it 'raises an ArgumentError error' do + expect { repository.get_patch_id('HEAD', nil) }.to raise_error(ArgumentError) + end + end + + context 'when two revisions are the same' do + it 'raises an Gitlab::Git::CommandError error' do + expect { repository.get_patch_id('HEAD', 'HEAD') }.to raise_error(Gitlab::Git::CommandError) + end + end + end end |