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

retrier_spec.rb « support « spec « qa - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1f303093a00411229f02bc1e5a5c28dbcbd8df75 (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
# frozen_string_literal: true

RSpec.describe QA::Support::Retrier do
  describe '.retry_until' do
    context 'when max_duration and max_attempts are nil' do
      it 'sets max attempts to 3 by default' do
        expect(subject).to receive(:repeat_until).with(hash_including(max_attempts: 3))

        subject.retry_until
      end
    end

    it 'sets sleep_interval to 0 by default' do
      expect(subject).to receive(:repeat_until).with(hash_including(sleep_interval: 0))

      subject.retry_until
    end

    it 'sets raise_on_failure to true by default' do
      expect(subject).to receive(:repeat_until).with(hash_including(raise_on_failure: true))

      subject.retry_until
    end

    it 'sets retry_on_exception to false by default' do
      expect(subject).to receive(:repeat_until).with(hash_including(retry_on_exception: false))

      subject.retry_until
    end

    it 'allows logs to be silenced' do
      expect(subject).to receive(:repeat_until).with(hash_including(log: false))

      subject.retry_until(log: false)
    end

    it 'sets custom error message' do
      expect(subject).to receive(:repeat_until).with(hash_including(message: 'Custom message'))

      subject.retry_until(message: 'Custom message')
    end
  end

  describe '.retry_on_exception' do
    it 'does not repeat if no exception is raised' do
      loop_counter = 0
      return_value = "test passed"

      expect(
        subject.retry_on_exception(max_attempts: 2) do
          loop_counter += 1
          return_value
        end
      ).to eq(return_value)
      expect(loop_counter).to eq(1)
    end

    it 'sets retry_on_exception to true' do
      expect(subject).to receive(:repeat_until).with(hash_including(retry_on_exception: true))

      subject.retry_on_exception
    end

    it 'sets max_attempts to 3 by default' do
      expect(subject).to receive(:repeat_until).with(hash_including(max_attempts: 3))

      subject.retry_on_exception
    end

    it 'sets sleep_interval to 0.5 by default' do
      expect(subject).to receive(:repeat_until).with(hash_including(sleep_interval: 0.5))

      subject.retry_on_exception
    end

    it 'allows logs to be silenced' do
      expect(subject).to receive(:repeat_until).with(hash_including(log: false))

      subject.retry_on_exception(log: false)
    end
  end
end