summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessio Caiazza <acaiazza@gitlab.com>2017-11-06 10:23:15 +0100
committerAlessio Caiazza <acaiazza@gitlab.com>2017-11-06 10:23:15 +0100
commit80b0834ae96480202678d8ca1e19c0ee4abf9001 (patch)
treea21e434355a170350086114cb0f89f9ab7785d73
parentc6c9b37b1d1c9304b0eef530adb4d32178adae16 (diff)
downloadgitlab-ce-80b0834ae96480202678d8ca1e19c0ee4abf9001.tar.gz
Add Clusters::Appplications::CheckInstallationProgressService tests
-rw-r--r--app/services/clusters/applications/check_installation_progress_service.rb4
-rw-r--r--spec/factories/clusters/applications/helm.rb5
-rw-r--r--spec/services/clusters/applications/check_installation_progress_service_spec.rb75
3 files changed, 82 insertions, 2 deletions
diff --git a/app/services/clusters/applications/check_installation_progress_service.rb b/app/services/clusters/applications/check_installation_progress_service.rb
index cf96c128c2e..81306a2ff5b 100644
--- a/app/services/clusters/applications/check_installation_progress_service.rb
+++ b/app/services/clusters/applications/check_installation_progress_service.rb
@@ -27,13 +27,13 @@ module Clusters
end
def on_failed
- app.make_errored!(log || 'Installation silently failed')
+ app.make_errored!(installation_errors || 'Installation silently failed')
finalize_installation
end
def check_timeout
if Time.now.utc - app.updated_at.to_time.utc > ClusterWaitForAppInstallationWorker::TIMEOUT
- app.make_errored!('App installation timeouted')
+ app.make_errored!('Installation timeouted')
else
ClusterWaitForAppInstallationWorker.perform_in(
ClusterWaitForAppInstallationWorker::INTERVAL, app.name, app.id)
diff --git a/spec/factories/clusters/applications/helm.rb b/spec/factories/clusters/applications/helm.rb
index 968a6a1a007..fd956097115 100644
--- a/spec/factories/clusters/applications/helm.rb
+++ b/spec/factories/clusters/applications/helm.rb
@@ -31,5 +31,10 @@ FactoryGirl.define do
status(-1)
status_reason 'something went wrong'
end
+
+ trait :timeouted do
+ installing
+ updated_at ClusterWaitForAppInstallationWorker::TIMEOUT.ago
+ end
end
end
diff --git a/spec/services/clusters/applications/check_installation_progress_service_spec.rb b/spec/services/clusters/applications/check_installation_progress_service_spec.rb
new file mode 100644
index 00000000000..c64c3a0c94c
--- /dev/null
+++ b/spec/services/clusters/applications/check_installation_progress_service_spec.rb
@@ -0,0 +1,75 @@
+require 'spec_helper'
+
+describe Clusters::Applications::CheckInstallationProgressService do
+ RESCHEDULE_PHASES = Gitlab::Kubernetes::Pod::PHASES - [Gitlab::Kubernetes::Pod::SUCCEEDED, Gitlab::Kubernetes::Pod::FAILED].freeze
+
+ def mock_helm_api(phase, errors: nil)
+ expect(service).to receive(:installation_phase).once.and_return(phase)
+ expect(service).to receive(:installation_errors).once.and_return(errors) if errors.present?
+ end
+
+ shared_examples 'not yet completed phase' do |phase|
+ context "when the installation POD phase is #{phase}" do
+ before do
+ mock_helm_api(phase)
+ end
+
+ context 'when not timeouted' do
+ it 'reschedule a new check' do
+ expect(ClusterWaitForAppInstallationWorker).to receive(:perform_in).once
+
+ service.execute
+
+ expect(application).to be_installing
+ expect(application.status_reason).to be_nil
+ end
+ end
+
+ context 'when timeouted' do
+ let(:application) { create(:applications_helm, :timeouted) }
+
+ it 'make the application errored' do
+ expect(ClusterWaitForAppInstallationWorker).not_to receive(:perform_in)
+
+ service.execute
+
+ expect(application).to be_errored
+ expect(application.status_reason).to match(/\btimeouted\b/)
+ end
+ end
+ end
+ end
+
+ describe '#execute' do
+ let(:application) { create(:applications_helm, :installing) }
+ let(:service) { described_class.new(application) }
+
+ context 'when installation POD succeeded' do
+ it 'make the application installed' do
+ mock_helm_api(Gitlab::Kubernetes::Pod::SUCCEEDED)
+ expect(service).to receive(:finalize_installation).once
+
+ service.execute
+
+ expect(application).to be_installed
+ expect(application.status_reason).to be_nil
+ end
+ end
+
+ context 'when installation POD failed' do
+ let(:error_message) { 'test installation failed' }
+
+ it 'make the application errored' do
+ mock_helm_api(Gitlab::Kubernetes::Pod::FAILED, errors: error_message)
+ expect(service).to receive(:finalize_installation).once
+
+ service.execute
+
+ expect(application).to be_errored
+ expect(application.status_reason).to eq(error_message)
+ end
+ end
+
+ RESCHEDULE_PHASES.each { |phase| it_behaves_like 'not yet completed phase', phase }
+ end
+end