diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-11 21:10:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-11 21:10:13 +0300 |
commit | e58ce90f147742c314b9cc08c2d1c0b585e39cf9 (patch) | |
tree | 467a1716bb63f4061e57b824c0e07532ca2fba4c /spec/models/ci/pipeline_schedule_spec.rb | |
parent | 62cd7010ef91dcaa5a5a36790985053db0b38671 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/ci/pipeline_schedule_spec.rb')
-rw-r--r-- | spec/models/ci/pipeline_schedule_spec.rb | 52 |
1 files changed, 37 insertions, 15 deletions
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 |