diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-11 18:10:13 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-11 18:10:13 +0000 |
commit | e58ce90f147742c314b9cc08c2d1c0b585e39cf9 (patch) | |
tree | 467a1716bb63f4061e57b824c0e07532ca2fba4c /spec/models | |
parent | 62cd7010ef91dcaa5a5a36790985053db0b38671 (diff) | |
download | gitlab-ce-e58ce90f147742c314b9cc08c2d1c0b585e39cf9.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/ci/build_spec.rb | 34 | ||||
-rw-r--r-- | spec/models/ci/pipeline_schedule_spec.rb | 52 | ||||
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 36 | ||||
-rw-r--r-- | spec/models/plan_limits_spec.rb | 1 |
4 files changed, 99 insertions, 24 deletions
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 600ddb784c5..11c2ecae68a 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1870,7 +1870,7 @@ RSpec.describe Ci::Build do end describe '#retryable?' do - subject { build.retryable? } + subject { build } context 'when build is retryable' do context 'when build is successful' do @@ -1878,7 +1878,7 @@ RSpec.describe Ci::Build do build.success! end - it { is_expected.to be_truthy } + it { is_expected.to be_retryable } end context 'when build is failed' do @@ -1886,7 +1886,7 @@ RSpec.describe Ci::Build do build.drop! end - it { is_expected.to be_truthy } + it { is_expected.to be_retryable } end context 'when build is canceled' do @@ -1894,7 +1894,7 @@ RSpec.describe Ci::Build do build.cancel! end - it { is_expected.to be_truthy } + it { is_expected.to be_retryable } end end @@ -1904,7 +1904,7 @@ RSpec.describe Ci::Build do build.run! end - it { is_expected.to be_falsey } + it { is_expected.not_to be_retryable } end context 'when build is skipped' do @@ -1912,7 +1912,7 @@ RSpec.describe Ci::Build do build.skip! end - it { is_expected.to be_falsey } + it { is_expected.not_to be_retryable } end context 'when build is degenerated' do @@ -1920,7 +1920,7 @@ RSpec.describe Ci::Build do build.degenerate! end - it { is_expected.to be_falsey } + it { is_expected.not_to be_retryable } end context 'when a canceled build has been retried already' do @@ -1931,7 +1931,7 @@ RSpec.describe Ci::Build do end context 'when prevent_retry_of_retried_jobs feature flag is enabled' do - it { is_expected.to be_falsey } + it { is_expected.not_to be_retryable } end context 'when prevent_retry_of_retried_jobs feature flag is disabled' do @@ -1939,7 +1939,7 @@ RSpec.describe Ci::Build do stub_feature_flags(prevent_retry_of_retried_jobs: false) end - it { is_expected.to be_truthy } + it { is_expected.to be_retryable } end end end @@ -5239,4 +5239,20 @@ RSpec.describe Ci::Build do end end end + + describe '.without_coverage' do + let!(:build_with_coverage) { create(:ci_build, pipeline: pipeline, coverage: 100.0) } + + it 'returns builds without coverage values' do + expect(described_class.without_coverage).to eq([build]) + end + end + + describe '.with_coverage_regex' do + let!(:build_with_coverage_regex) { create(:ci_build, pipeline: pipeline, coverage_regex: '\d') } + + it 'returns builds with coverage regex values' do + expect(described_class.with_coverage_regex).to eq([build_with_coverage_regex]) + end + end end diff --git a/spec/models/ci/pipeline_schedule_spec.rb b/spec/models/ci/pipeline_schedule_spec.rb index d5560edbbfd..33baba30fd8 100644 --- a/spec/models/ci/pipeline_schedule_spec.rb +++ b/spec/models/ci/pipeline_schedule_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe Ci::PipelineSchedule do + let_it_be(:project) { create_default(:project) } + subject { build(:ci_pipeline_schedule) } it { is_expected.to belong_to(:project) } @@ -18,7 +20,7 @@ RSpec.describe Ci::PipelineSchedule do it { is_expected.to respond_to(:next_run_at) } it_behaves_like 'includes Limitable concern' do - subject { build(:ci_pipeline_schedule) } + subject { build(:ci_pipeline_schedule, project: project) } end describe 'validations' do @@ -103,26 +105,46 @@ RSpec.describe Ci::PipelineSchedule do end describe '#set_next_run_at' do - let(:pipeline_schedule) { create(:ci_pipeline_schedule, :nightly) } - let(:ideal_next_run_at) { pipeline_schedule.send(:ideal_next_run_from, Time.zone.now) } - let(:cron_worker_next_run_at) { pipeline_schedule.send(:cron_worker_next_run_from, Time.zone.now) } + using RSpec::Parameterized::TableSyntax + + where(:worker_cron, :schedule_cron, :plan_limit, :ff_enabled, :now, :result) do + '0 1 2 3 *' | '0 1 * * *' | nil | true | Time.zone.local(2021, 3, 2, 1, 0) | Time.zone.local(2022, 3, 2, 1, 0) + '0 1 2 3 *' | '0 1 * * *' | (1.day.in_minutes / 1.hour.in_minutes).to_i | true | Time.zone.local(2021, 3, 2, 1, 0) | Time.zone.local(2022, 3, 2, 1, 0) + '0 1 2 3 *' | '0 1 * * *' | (1.day.in_minutes / 1.hour.in_minutes).to_i | false | Time.zone.local(2021, 3, 2, 1, 0) | Time.zone.local(2022, 3, 2, 1, 0) + '*/5 * * * *' | '*/1 * * * *' | nil | true | Time.zone.local(2021, 5, 27, 11, 0) | Time.zone.local(2021, 5, 27, 11, 5) + '*/5 * * * *' | '*/1 * * * *' | (1.day.in_minutes / 1.hour.in_minutes).to_i | true | Time.zone.local(2021, 5, 27, 11, 0) | Time.zone.local(2021, 5, 27, 12, 0) + '*/5 * * * *' | '*/1 * * * *' | (1.day.in_minutes / 1.hour.in_minutes).to_i | false | Time.zone.local(2021, 5, 27, 11, 0) | Time.zone.local(2021, 5, 27, 11, 5) + '*/5 * * * *' | '*/1 * * * *' | (1.day.in_minutes / 10).to_i | true | Time.zone.local(2021, 5, 27, 11, 0) | Time.zone.local(2021, 5, 27, 11, 10) + '*/5 * * * *' | '*/1 * * * *' | 200 | true | Time.zone.local(2021, 5, 27, 11, 0) | Time.zone.local(2021, 5, 27, 11, 10) + '*/5 * * * *' | '*/1 * * * *' | 200 | false | Time.zone.local(2021, 5, 27, 11, 0) | Time.zone.local(2021, 5, 27, 11, 5) + '*/5 * * * *' | '0 * * * *' | nil | true | Time.zone.local(2021, 5, 27, 11, 0) | Time.zone.local(2021, 5, 27, 12, 5) + '*/5 * * * *' | '0 * * * *' | (1.day.in_minutes / 10).to_i | true | Time.zone.local(2021, 5, 27, 11, 0) | Time.zone.local(2021, 5, 27, 12, 0) + '*/5 * * * *' | '0 * * * *' | (1.day.in_minutes / 10).to_i | false | Time.zone.local(2021, 5, 27, 11, 0) | Time.zone.local(2021, 5, 27, 12, 5) + '*/5 * * * *' | '0 * * * *' | (1.day.in_minutes / 1.hour.in_minutes).to_i | true | Time.zone.local(2021, 5, 27, 11, 0) | Time.zone.local(2021, 5, 27, 12, 0) + '*/5 * * * *' | '0 * * * *' | (1.day.in_minutes / 2.hours.in_minutes).to_i | true | Time.zone.local(2021, 5, 27, 11, 0) | Time.zone.local(2021, 5, 27, 12, 5) + end + + with_them do + let(:pipeline_schedule) { create(:ci_pipeline_schedule, cron: schedule_cron) } - context 'when PipelineScheduleWorker runs at a specific interval' do before do allow(Settings).to receive(:cron_jobs) do - { - 'pipeline_schedule_worker' => { - 'cron' => '0 1 2 3 *' - } - } + { 'pipeline_schedule_worker' => { 'cron' => worker_cron } } end + + create(:plan_limits, :default_plan, ci_daily_pipeline_schedule_triggers: plan_limit) if plan_limit + stub_feature_flags(ci_daily_limit_for_pipeline_schedules: false) unless ff_enabled + + # Setting this here to override initial save with the current time + pipeline_schedule.next_run_at = now end - it "updates next_run_at to the sidekiq worker's execution time" do - expect(pipeline_schedule.next_run_at.min).to eq(0) - expect(pipeline_schedule.next_run_at.hour).to eq(1) - expect(pipeline_schedule.next_run_at.day).to eq(2) - expect(pipeline_schedule.next_run_at.month).to eq(3) + it 'updates next_run_at' do + travel_to(now) do + pipeline_schedule.set_next_run_at + + expect(pipeline_schedule.next_run_at).to eq(result) + end end end diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 024ac1b8094..72af40e31e0 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -744,6 +744,42 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do end end + describe '#update_builds_coverage' do + let_it_be(:pipeline) { create(:ci_empty_pipeline) } + + context 'builds with coverage_regex defined' do + let!(:build_1) { create(:ci_build, :success, :trace_with_coverage, trace_coverage: 60.0, pipeline: pipeline) } + let!(:build_2) { create(:ci_build, :success, :trace_with_coverage, trace_coverage: 80.0, pipeline: pipeline) } + + it 'updates the coverage value of each build from the trace' do + pipeline.update_builds_coverage + + expect(build_1.reload.coverage).to eq(60.0) + expect(build_2.reload.coverage).to eq(80.0) + end + end + + context 'builds without coverage_regex defined' do + let!(:build) { create(:ci_build, :success, :trace_with_coverage, coverage_regex: nil, trace_coverage: 60.0, pipeline: pipeline) } + + it 'does not update the coverage value of each build from the trace' do + pipeline.update_builds_coverage + + expect(build.reload.coverage).to eq(nil) + end + end + + context 'builds with coverage values already present' do + let!(:build) { create(:ci_build, :success, :trace_with_coverage, trace_coverage: 60.0, coverage: 10.0, pipeline: pipeline) } + + it 'does not update the coverage value of each build from the trace' do + pipeline.update_builds_coverage + + expect(build.reload.coverage).to eq(10.0) + end + end + end + describe '#retryable?' do subject { pipeline.retryable? } diff --git a/spec/models/plan_limits_spec.rb b/spec/models/plan_limits_spec.rb index b8c723b3847..cf8e30023eb 100644 --- a/spec/models/plan_limits_spec.rb +++ b/spec/models/plan_limits_spec.rb @@ -211,6 +211,7 @@ RSpec.describe PlanLimits do storage_size_limit daily_invites web_hook_calls + ci_daily_pipeline_schedule_triggers ] + disabled_max_artifact_size_columns end |