summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/job_waiter_spec.rb
blob: 6186cec268993200b7cd0b4334fbb503fd530a69 (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
require 'spec_helper'

describe Gitlab::JobWaiter do
  describe '#wait' do
    let(:waiter) { described_class.new(%w(a)) }
    it 'returns when all jobs have been completed' do
      expect(Gitlab::SidekiqStatus).to receive(:all_completed?).with(%w(a))
        .and_return(true)

      expect(waiter).not_to receive(:sleep)

      waiter.wait
    end

    it 'sleeps between checking the job statuses' do
      expect(Gitlab::SidekiqStatus).to receive(:all_completed?)
        .with(%w(a))
        .and_return(false, true)

      expect(waiter).to receive(:sleep).with(described_class::INTERVAL)

      waiter.wait
    end

    it 'returns when timing out' do
      expect(waiter).not_to receive(:sleep)
      waiter.wait(0)
    end
  end
end