Welcome to mirror list, hosted at ThFree Co, Russian Federation.

check_upgrade_progress_service_spec.rb « applications « clusters « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dbde8cec9b9ace171b6d4e47aa27b529bc35fc3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Clusters::Applications::CheckUpgradeProgressService do
  reschedule_phashes = ::Gitlab::Kubernetes::Pod::PHASES -
    [::Gitlab::Kubernetes::Pod::SUCCEEDED, ::Gitlab::Kubernetes::Pod::FAILED, ::Gitlab].freeze

  let(:application) { create(:clusters_applications_prometheus, :updating) }
  let(:service) { described_class.new(application) }
  let(:phase) { ::Gitlab::Kubernetes::Pod::UNKNOWN }
  let(:errors) { nil }

  shared_examples 'a terminated upgrade' do
    it 'removes the POD' do
      expect(service).to receive(:remove_pod).once

      service.execute
    end
  end

  shared_examples 'a not yet terminated upgrade' do |a_phase|
    let(:phase) { a_phase }

    context "when phase is #{a_phase}" do
      context 'when not timed out' do
        it 'reschedule a new check' do
          expect(::ClusterWaitForAppUpdateWorker).to receive(:perform_in).once
          expect(service).not_to receive(:remove_pod)

          service.execute

          expect(application).to be_updating
          expect(application.status_reason).to be_nil
        end
      end

      context 'when timed out' do
        let(:application) { create(:clusters_applications_prometheus, :timed_out, :updating) }

        it_behaves_like 'a terminated upgrade'

        it 'make the application update errored' do
          expect(::ClusterWaitForAppUpdateWorker).not_to receive(:perform_in)

          service.execute

          expect(application).to be_update_errored
          expect(application.status_reason).to eq("Update timed out")
        end
      end
    end
  end

  before do
    allow(service).to receive(:phase).once.and_return(phase)

    allow(service).to receive(:errors).and_return(errors)
    allow(service).to receive(:remove_pod).and_return(nil)
  end

  describe '#execute' do
    context 'when upgrade pod succeeded' do
      let(:phase) { ::Gitlab::Kubernetes::Pod::SUCCEEDED }

      it_behaves_like 'a terminated upgrade'

      it 'make the application upgraded' do
        expect(::ClusterWaitForAppUpdateWorker).not_to receive(:perform_in)

        service.execute

        expect(application).to be_updated
        expect(application.status_reason).to be_nil
      end
    end

    context 'when upgrade pod failed' do
      let(:phase) { ::Gitlab::Kubernetes::Pod::FAILED }
      let(:errors) { 'test installation failed' }

      it_behaves_like 'a terminated upgrade'

      it 'make the application update errored' do
        service.execute

        expect(application).to be_update_errored
        expect(application.status_reason).to eq(errors)
      end
    end

    reschedule_phashes.each { |phase| it_behaves_like 'a not yet terminated upgrade', phase }
  end
end