2020-05-24 23:13:21 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Ci::FreezePeriodStatus do
|
2020-05-24 23:13:21 +05:30
|
|
|
let(:project) { create :project }
|
|
|
|
# '0 23 * * 5' == "At 23:00 on Friday."", '0 7 * * 1' == "At 07:00 on Monday.""
|
|
|
|
let(:friday_2300) { '0 23 * * 5' }
|
|
|
|
let(:monday_0700) { '0 7 * * 1' }
|
|
|
|
|
|
|
|
subject { described_class.new(project: project).execute }
|
|
|
|
|
|
|
|
shared_examples 'within freeze period' do |time|
|
|
|
|
it 'is frozen' do
|
2021-01-03 14:25:43 +05:30
|
|
|
travel_to(time) do
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(subject).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'outside freeze period' do |time|
|
|
|
|
it 'is not frozen' do
|
2021-01-03 14:25:43 +05:30
|
|
|
travel_to(time) do
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(subject).to be_falsy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'single freeze period' do
|
|
|
|
let!(:freeze_period) { create(:ci_freeze_period, project: project, freeze_start: friday_2300, freeze_end: monday_0700) }
|
|
|
|
|
|
|
|
it_behaves_like 'outside freeze period', Time.utc(2020, 4, 10, 22, 59)
|
|
|
|
|
|
|
|
it_behaves_like 'within freeze period', Time.utc(2020, 4, 10, 23, 1)
|
|
|
|
|
|
|
|
it_behaves_like 'within freeze period', Time.utc(2020, 4, 13, 6, 59)
|
|
|
|
|
|
|
|
it_behaves_like 'outside freeze period', Time.utc(2020, 4, 13, 7, 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'multiple freeze periods' do
|
|
|
|
# '30 23 * * 5' == "At 23:30 on Friday."", '0 8 * * 1' == "At 08:00 on Monday.""
|
|
|
|
let(:friday_2330) { '30 23 * * 5' }
|
|
|
|
let(:monday_0800) { '0 8 * * 1' }
|
|
|
|
|
|
|
|
let!(:freeze_period_1) { create(:ci_freeze_period, project: project, freeze_start: friday_2300, freeze_end: monday_0700) }
|
|
|
|
let!(:freeze_period_2) { create(:ci_freeze_period, project: project, freeze_start: friday_2330, freeze_end: monday_0800) }
|
|
|
|
|
|
|
|
it_behaves_like 'outside freeze period', Time.utc(2020, 4, 10, 22, 59)
|
|
|
|
|
|
|
|
it_behaves_like 'within freeze period', Time.utc(2020, 4, 10, 23, 29)
|
|
|
|
|
|
|
|
it_behaves_like 'within freeze period', Time.utc(2020, 4, 11, 10, 0)
|
|
|
|
|
|
|
|
it_behaves_like 'within freeze period', Time.utc(2020, 4, 10, 23, 1)
|
|
|
|
|
|
|
|
it_behaves_like 'within freeze period', Time.utc(2020, 4, 13, 6, 59)
|
|
|
|
|
|
|
|
it_behaves_like 'within freeze period', Time.utc(2020, 4, 13, 7, 59)
|
|
|
|
|
|
|
|
it_behaves_like 'outside freeze period', Time.utc(2020, 4, 13, 8, 1)
|
|
|
|
end
|
2022-10-11 01:57:18 +05:30
|
|
|
|
|
|
|
# https://gitlab.com/gitlab-org/gitlab/-/issues/370472
|
|
|
|
context 'when period overlaps with itself' do
|
|
|
|
let!(:freeze_period) { create(:ci_freeze_period, project: project, freeze_start: '* * * 8 *', freeze_end: '* * * 10 *') }
|
|
|
|
|
|
|
|
it_behaves_like 'within freeze period', Time.utc(2020, 8, 11, 0, 0)
|
|
|
|
|
|
|
|
it_behaves_like 'outside freeze period', Time.utc(2020, 10, 11, 0, 0)
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|