summaryrefslogtreecommitdiff
path: root/spec/bin/sidekiq_cluster_spec.rb
blob: eb014c511e344fc26918e2fe7a7979266dcf567a (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# frozen_string_literal: true

require 'fast_spec_helper'
require 'shellwords'
require 'rspec-parameterized'

RSpec.describe 'bin/sidekiq-cluster', :aggregate_failures do
  using RSpec::Parameterized::TableSyntax

  let(:root) { File.expand_path('../..', __dir__) }

  context 'when selecting some queues and excluding others' do
    where(:args, :included, :excluded) do
      %w[--negate cronjob] | '-qdefault,1' | '-qcronjob,1'
      %w[--queue-selector resource_boundary=cpu] | '-qupdate_merge_requests,1' | '-qdefault,1'
    end

    with_them do
      it 'runs successfully' do
        cmd = %w[bin/sidekiq-cluster --dryrun] + args

        output, status = Gitlab::Popen.popen(cmd, root)

        expect(status).to be(0)
        expect(output).to include('bundle exec sidekiq')
        expect(Shellwords.split(output)).to include(included)
        expect(Shellwords.split(output)).not_to include(excluded)
      end
    end
  end

  context 'when selecting all queues' do
    [
      %w[*],
      %w[--queue-selector *]
    ].each do |args|
      it "runs successfully with `#{args}`" do
        cmd = %w[bin/sidekiq-cluster --dryrun] + args

        output, status = Gitlab::Popen.popen(cmd, root)

        expect(status).to be(0)
        expect(output).to include('bundle exec sidekiq')
        expect(Shellwords.split(output)).to include('-qdefault,1')
        expect(Shellwords.split(output)).to include('-qcronjob:ci_archive_traces_cron,1')
      end
    end
  end

  context 'when arguments contain newlines' do
    it 'raises an error' do
      [
        ["default\n"],
        ["defaul\nt"]
      ].each do |args|
        cmd = %w[bin/sidekiq-cluster --dryrun] + args

        output, status = Gitlab::Popen.popen(cmd, root)

        expect(status).to be(1)
        expect(output).to include('cannot contain newlines')
      end
    end
  end
end