diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
commit | a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch) | |
tree | fb69158581673816a8cd895f9d352dcb3c678b1e /spec/models/ci/pipeline_schedule_spec.rb | |
parent | d16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff) |
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'spec/models/ci/pipeline_schedule_spec.rb')
-rw-r--r-- | spec/models/ci/pipeline_schedule_spec.rb | 77 |
1 files changed, 62 insertions, 15 deletions
diff --git a/spec/models/ci/pipeline_schedule_spec.rb b/spec/models/ci/pipeline_schedule_spec.rb index d5560edbbfd..cf73460bf1e 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,49 @@ 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) + '*/5 * * * *' | '0 1 * * *' | (1.day.in_minutes / 1.hour.in_minutes).to_i | true | Time.zone.local(2021, 5, 27, 1, 0) | Time.zone.local(2021, 5, 28, 1, 0) + '*/5 * * * *' | '0 1 * * *' | (1.day.in_minutes / 1.hour.in_minutes).to_i | true | Time.zone.local(2021, 5, 27, 1, 0) | Time.zone.local(2021, 5, 28, 1, 0) + '*/5 * * * *' | '0 1 1 * *' | (1.day.in_minutes / 1.hour.in_minutes).to_i | true | Time.zone.local(2021, 5, 1, 1, 0) | Time.zone.local(2021, 6, 1, 1, 0) + 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 @@ -176,4 +201,26 @@ RSpec.describe Ci::PipelineSchedule do it { is_expected.to contain_exactly(*pipeline_schedule_variables.map(&:to_runner_variable)) } end + + describe '#daily_limit' do + let(:pipeline_schedule) { build(:ci_pipeline_schedule) } + + subject(:daily_limit) { pipeline_schedule.daily_limit } + + context 'when there is no limit' do + before do + create(:plan_limits, :default_plan, ci_daily_pipeline_schedule_triggers: 0) + end + + it { is_expected.to be_nil } + end + + context 'when there is a limit' do + before do + create(:plan_limits, :default_plan, ci_daily_pipeline_schedule_triggers: 144) + end + + it { is_expected.to eq(144) } + end + end end |