2020-03-11 20:09:34 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-09-01 20:10:56 -04:00
|
|
|
require 'fast_spec_helper'
|
2020-03-20 17:09:17 -04:00
|
|
|
require 'shellwords'
|
2021-09-01 20:10:56 -04:00
|
|
|
require 'rspec-parameterized'
|
2020-03-11 20:09:34 -04:00
|
|
|
|
2021-09-01 20:10:56 -04:00
|
|
|
RSpec.describe 'bin/sidekiq-cluster', :aggregate_failures do
|
2020-03-11 20:09:34 -04:00
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
2021-09-01 20:10:56 -04:00
|
|
|
let(:root) { File.expand_path('../..', __dir__) }
|
|
|
|
|
2020-03-11 20:09:34 -04:00
|
|
|
context 'when selecting some queues and excluding others' do
|
|
|
|
where(:args, :included, :excluded) do
|
|
|
|
%w[--negate cronjob] | '-qdefault,1' | '-qcronjob,1'
|
2020-11-03 01:08:58 -05:00
|
|
|
%w[--queue-selector resource_boundary=cpu] | '-qupdate_merge_requests,1' | '-qdefault,1'
|
2020-03-11 20:09:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
2021-09-01 20:10:56 -04:00
|
|
|
it 'runs successfully' do
|
2020-03-11 20:09:34 -04:00
|
|
|
cmd = %w[bin/sidekiq-cluster --dryrun] + args
|
|
|
|
|
2021-09-01 20:10:56 -04:00
|
|
|
output, status = Gitlab::Popen.popen(cmd, root)
|
2020-03-11 20:09:34 -04:00
|
|
|
|
|
|
|
expect(status).to be(0)
|
2020-03-20 17:09:17 -04:00
|
|
|
expect(output).to include('bundle exec sidekiq')
|
|
|
|
expect(Shellwords.split(output)).to include(included)
|
|
|
|
expect(Shellwords.split(output)).not_to include(excluded)
|
2020-03-11 20:09:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when selecting all queues' do
|
|
|
|
[
|
|
|
|
%w[*],
|
2021-06-08 08:10:09 -04:00
|
|
|
%w[--queue-selector *]
|
2020-03-11 20:09:34 -04:00
|
|
|
].each do |args|
|
2021-09-01 20:10:56 -04:00
|
|
|
it "runs successfully with `#{args}`" do
|
2020-03-11 20:09:34 -04:00
|
|
|
cmd = %w[bin/sidekiq-cluster --dryrun] + args
|
|
|
|
|
2021-09-01 20:10:56 -04:00
|
|
|
output, status = Gitlab::Popen.popen(cmd, root)
|
2020-03-11 20:09:34 -04:00
|
|
|
|
|
|
|
expect(status).to be(0)
|
2020-03-20 17:09:17 -04:00
|
|
|
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')
|
2020-03-11 20:09:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-09-01 20:10:56 -04:00
|
|
|
|
|
|
|
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
|
2020-03-11 20:09:34 -04:00
|
|
|
end
|