summaryrefslogtreecommitdiff
path: root/spec/services/ci/update_build_queue_service_spec.rb
blob: efefa8e8ecab6a9488e98ae5b2069f598f0f4ad5 (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
require 'spec_helper'

describe Ci::UpdateBuildQueueService, :services do
  let(:project) { create(:project, :repository) }
  let(:build) { create(:ci_build, pipeline: pipeline) }
  let(:pipeline) { create(:ci_pipeline, project: project) }

  context 'when updating specific runners' do
    let(:runner) { create(:ci_runner) }

    context 'when there are runner that can pick build' do
      before do
        build.project.runners << runner
      end

      it 'ticks runner queue value' do
        expect { subject.execute(build) }
          .to change { runner.ensure_runner_queue_value }
      end
    end

    context 'when there are no runners that can pick build' do
      it 'does not tick runner queue value' do
        expect { subject.execute(build) }
          .not_to change { runner.ensure_runner_queue_value }
      end
    end
  end

  context 'when updating shared runners' do
    let(:runner) { create(:ci_runner, :shared) }

    context 'when there are runner that can pick build' do
      it 'ticks runner queue value' do
        expect { subject.execute(build) }
          .to change { runner.ensure_runner_queue_value }
      end
    end

    context 'when there are no runners that can pick build' do
      before do
        build.tag_list = [:docker]
      end

      it 'does not tick runner queue value' do
        expect { subject.execute(build) }
          .not_to change { runner.ensure_runner_queue_value }
      end
    end
  end
end