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

project_export_shared_examples.rb « workers « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 175ef9bd012ebb0f0b2879aab6719305fdcc30f1 (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
95
96
97
98
# frozen_string_literal: true

RSpec.shared_examples 'export worker' do
  describe '#perform' do
    let!(:user) { create(:user) }
    let!(:project) { create(:project) }

    before do
      allow_next_instance_of(described_class) do |job|
        allow(job).to receive(:jid).and_return(SecureRandom.hex(8))
      end
    end

    context 'when it succeeds' do
      it 'calls the ExportService' do
        expect_next_instance_of(::Projects::ImportExport::ExportService) do |service|
          expect(service).to receive(:execute)
        end

        subject.perform(user.id, project.id, { 'klass' => 'Gitlab::ImportExport::AfterExportStrategies::DownloadNotificationStrategy' })
      end

      context 'export job' do
        before do
          allow_next_instance_of(::Projects::ImportExport::ExportService) do |service|
            allow(service).to receive(:execute)
          end
        end

        it 'creates an export job record for the project' do
          expect { subject.perform(user.id, project.id, {}) }.to change { project.export_jobs.count }.from(0).to(1)
        end

        it 'sets the export job status to started' do
          expect_next_instance_of(ProjectExportJob) do |job|
            expect(job).to receive(:start)
          end

          subject.perform(user.id, project.id, {})
        end

        it 'sets the export job status to finished' do
          expect_next_instance_of(ProjectExportJob) do |job|
            expect(job).to receive(:finish)
          end

          subject.perform(user.id, project.id, {})
        end
      end
    end

    context 'when it fails' do
      it 'does not raise an exception when strategy is invalid' do
        expect(::Projects::ImportExport::ExportService).not_to receive(:new)

        expect_next_instance_of(ProjectExportJob) do |job|
          expect(job).to receive(:finish)
        end

        expect { subject.perform(user.id, project.id, { 'klass' => 'Whatever' }) }.not_to raise_error
      end

      it 'does not raise error when project cannot be found' do
        expect { subject.perform(user.id, non_existing_record_id, {}) }.not_to raise_error
      end

      it 'does not raise error when user cannot be found' do
        expect { subject.perform(non_existing_record_id, project.id, {}) }.not_to raise_error
      end

      it 'fails the export job status' do
        expect_next_instance_of(::Projects::ImportExport::ExportService) do |service|
          expect(service).to receive(:execute).and_raise(Gitlab::ImportExport::Error)
        end

        expect_next_instance_of(ProjectExportJob) do |job|
          expect(job).to receive(:fail_op)
        end

        expect { subject.perform(user.id, project.id, {}) }.to raise_error(Gitlab::ImportExport::Error)
      end
    end
  end

  describe 'sidekiq options' do
    it 'disables retry' do
      expect(described_class.sidekiq_options['retry']).to eq(false)
    end

    it 'disables dead' do
      expect(described_class.sidekiq_options['dead']).to eq(false)
    end

    it 'sets default status expiration' do
      expect(described_class.sidekiq_options['status_expiration']).to eq(StuckExportJobsWorker::EXPORT_JOBS_EXPIRATION)
    end
  end
end