debian-mirror-gitlab/spec/services/clusters/applications/schedule_update_service_spec.rb

64 lines
2.1 KiB
Ruby
Raw Normal View History

2020-04-22 19:07:51 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Clusters::Applications::ScheduleUpdateService do
2020-04-22 19:07:51 +05:30
describe '#execute' do
let(:project) { create(:project) }
around do |example|
2020-11-24 15:15:51 +05:30
freeze_time { example.run }
2020-04-22 19:07:51 +05:30
end
2021-06-08 01:23:25 +05:30
context 'when the application is a Clusters::Integrations::Prometheus' do
let(:application) { create(:clusters_integrations_prometheus) }
it 'does nothing' do
service = described_class.new(application, project)
expect(::ClusterUpdateAppWorker).not_to receive(:perform_in)
expect(::ClusterUpdateAppWorker).not_to receive(:perform_async)
service.execute
end
end
context 'when the application is externally installed' do
let(:application) { create(:clusters_applications_prometheus, :externally_installed) }
it 'does nothing' do
service = described_class.new(application, project)
expect(::ClusterUpdateAppWorker).not_to receive(:perform_in)
expect(::ClusterUpdateAppWorker).not_to receive(:perform_async)
service.execute
end
end
2020-04-22 19:07:51 +05:30
context 'when application is able to be updated' do
context 'when the application was recently scheduled' do
it 'schedules worker with a backoff delay' do
2020-05-24 23:13:21 +05:30
application = create(:clusters_applications_prometheus, :installed, last_update_started_at: Time.current + 5.minutes)
2020-04-22 19:07:51 +05:30
service = described_class.new(application, project)
2020-05-24 23:13:21 +05:30
expect(::ClusterUpdateAppWorker).to receive(:perform_in).with(described_class::BACKOFF_DELAY, application.name, application.id, project.id, Time.current).once
2020-04-22 19:07:51 +05:30
service.execute
end
end
context 'when the application has not been recently updated' do
it 'schedules worker' do
application = create(:clusters_applications_prometheus, :installed)
service = described_class.new(application, project)
2020-05-24 23:13:21 +05:30
expect(::ClusterUpdateAppWorker).to receive(:perform_async).with(application.name, application.id, project.id, Time.current).once
2020-04-22 19:07:51 +05:30
service.execute
end
end
end
end
end