job_waiter_spec.rb 1 KB
Newer Older
1 2 3
require 'spec_helper'

describe Gitlab::JobWaiter do
4 5 6 7
  describe '.notify' do
    it 'pushes the jid to the named queue' do
      key = 'gitlab:job_waiter:foo'
      jid = 1
8

9 10 11
      redis = double('redis')
      expect(Gitlab::Redis::SharedState).to receive(:with).and_yield(redis)
      expect(redis).to receive(:lpush).with(key, jid)
12

13
      described_class.notify(key, jid)
14
    end
15 16 17 18
  end

  describe '#wait' do
    let(:waiter) { described_class.new(2) }
19

20 21 22
    it 'returns when all jobs have been completed' do
      described_class.notify(waiter.key, 'a')
      described_class.notify(waiter.key, 'b')
23

24 25
      result = nil
      expect { Timeout.timeout(1) { result = waiter.wait(2) } }.not_to raise_error
26

27
      expect(result).to contain_exactly('a', 'b')
28 29
    end

30 31 32 33 34 35 36
    it 'times out if not all jobs complete' do
      described_class.notify(waiter.key, 'a')

      result = nil
      expect { Timeout.timeout(2) { result = waiter.wait(1) } }.not_to raise_error

      expect(result).to contain_exactly('a')
37 38 39
    end
  end
end