BigW Consortium Gitlab

sidekiq_status_spec.rb 2.22 KB
Newer Older
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
require 'spec_helper'

describe Gitlab::SidekiqStatus do
  describe '.set', :redis do
    it 'stores the job ID' do
      described_class.set('123')

      key = described_class.key_for('123')

      Sidekiq.redis do |redis|
        expect(redis.exists(key)).to eq(true)
        expect(redis.ttl(key) > 0).to eq(true)
      end
    end
  end

  describe '.unset', :redis do
    it 'removes the job ID' do
      described_class.set('123')
      described_class.unset('123')

      key = described_class.key_for('123')

      Sidekiq.redis do |redis|
        expect(redis.exists(key)).to eq(false)
      end
    end
  end

  describe '.all_completed?', :redis do
    it 'returns true if all jobs have been completed' do
      expect(described_class.all_completed?(%w(123))).to eq(true)
    end

    it 'returns false if a job has not yet been completed' do
      described_class.set('123')

      expect(described_class.all_completed?(%w(123 456))).to eq(false)
    end
  end

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
  describe '.num_running', :redis do
    it 'returns 0 if all jobs have been completed' do
      expect(described_class.num_running(%w(123))).to eq(0)
    end

    it 'returns 2 if two jobs are still running' do
      described_class.set('123')
      described_class.set('456')

      expect(described_class.num_running(%w(123 456 789))).to eq(2)
    end
  end

  describe '.num_completed', :redis do
    it 'returns 1 if all jobs have been completed' do
      expect(described_class.num_completed(%w(123))).to eq(1)
    end

    it 'returns 1 if a job has not yet been completed' do
      described_class.set('123')
      described_class.set('456')

      expect(described_class.num_completed(%w(123 456 789))).to eq(1)
    end
  end

68 69 70 71 72 73 74 75
  describe '.key_for' do
    it 'returns the key for a job ID' do
      key = described_class.key_for('123')

      expect(key).to be_an_instance_of(String)
      expect(key).to include('123')
    end
  end
76 77 78 79 80 81 82 83 84 85 86 87 88

  describe 'completed', :redis do
    it 'returns the completed job' do
      expect(described_class.completed_jids(%w(123))).to eq(['123'])
    end

    it 'returns only the jobs completed' do
      described_class.set('123')
      described_class.set('456')

      expect(described_class.completed_jids(%w(123 456 789))).to eq(['789'])
    end
  end
89
end