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

worker_state_spec.rb « phabricator_import « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4a07e28440fe7ebddabe64d2a66bbb06fe5b5689 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::PhabricatorImport::WorkerState, :clean_gitlab_redis_shared_state do
  subject(:state) { described_class.new('weird-project-id') }

  let(:key) { 'phabricator-import/jobs/project-weird-project-id/job-count' }

  describe '#add_job' do
    it 'increments the counter for jobs' do
      set_value(3)

      expect { state.add_job }.to change { get_value }.from('3').to('4')
    end
  end

  describe '#remove_job' do
    it 'decrements the counter for jobs' do
      set_value(3)

      expect { state.remove_job }.to change { get_value }.from('3').to('2')
    end
  end

  describe '#running_count' do
    it 'reads the value' do
      set_value(9)

      expect(state.running_count).to eq(9)
    end

    it 'returns 0 when nothing was set' do
      expect(state.running_count).to eq(0)
    end
  end

  def set_value(value)
    redis.with { |r| r.set(key, value) }
  end

  def get_value
    redis.with { |r| r.get(key) }
  end

  def redis
    Gitlab::Redis::SharedState
  end
end