2019-12-22 04:07:51 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::Runtime do
|
2020-02-06 13:08:54 -05:00
|
|
|
shared_examples "valid runtime" do |runtime, max_threads|
|
|
|
|
it "identifies itself" do
|
|
|
|
expect(subject.identify).to eq(runtime)
|
|
|
|
expect(subject.public_send("#{runtime}?")).to be(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not identify as others" do
|
|
|
|
(described_class::AVAILABLE_RUNTIMES - [runtime]).each do |runtime|
|
|
|
|
expect(subject.public_send("#{runtime}?")).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "reports its maximum concurrency" do
|
|
|
|
expect(subject.max_threads).to eq(max_threads)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-27 13:08:12 -05:00
|
|
|
before do
|
|
|
|
allow(described_class).to receive(:process_name).and_return('ruby')
|
2020-01-31 07:08:33 -05:00
|
|
|
stub_rails_env('production')
|
2019-12-27 13:08:12 -05:00
|
|
|
end
|
|
|
|
|
2019-12-22 04:07:51 -05:00
|
|
|
context "when unknown" do
|
|
|
|
it "raises an exception when trying to identify" do
|
|
|
|
expect { subject.identify }.to raise_error(subject::UnknownProcessError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "on multiple matches" do
|
|
|
|
before do
|
|
|
|
stub_const('::Puma', double)
|
|
|
|
stub_const('::Rails::Console', double)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "raises an exception when trying to identify" do
|
|
|
|
expect { subject.identify }.to raise_error(subject::AmbiguousProcessError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-11 02:10:29 -04:00
|
|
|
# Puma has no cli_config method unless `puma/cli` is required
|
|
|
|
context "puma without cli_config" do
|
|
|
|
let(:puma_type) { double('::Puma') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_const('::Puma', puma_type)
|
|
|
|
end
|
|
|
|
|
2021-10-27 08:09:41 -04:00
|
|
|
it_behaves_like "valid runtime", :puma, 1 + Gitlab::ActionCable::Config.worker_pool_size
|
2021-05-11 02:10:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "puma with cli_config" do
|
2019-12-22 04:07:51 -05:00
|
|
|
let(:puma_type) { double('::Puma') }
|
2021-02-16 10:09:50 -05:00
|
|
|
let(:max_workers) { 2 }
|
2019-12-22 04:07:51 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
stub_const('::Puma', puma_type)
|
2021-02-16 10:09:50 -05:00
|
|
|
allow(puma_type).to receive_message_chain(:cli_config, :options).and_return(max_threads: 2, workers: max_workers)
|
2019-12-22 04:07:51 -05:00
|
|
|
end
|
|
|
|
|
2021-10-27 08:09:41 -04:00
|
|
|
it_behaves_like "valid runtime", :puma, 3 + Gitlab::ActionCable::Config.worker_pool_size
|
2020-07-08 02:09:13 -04:00
|
|
|
|
2021-10-27 08:09:41 -04:00
|
|
|
context "when ActionCable worker pool size is configured" do
|
2020-07-08 02:09:13 -04:00
|
|
|
before do
|
2021-10-27 08:09:41 -04:00
|
|
|
stub_env('ACTION_CABLE_WORKER_POOL_SIZE', 10)
|
2020-07-08 02:09:13 -04:00
|
|
|
end
|
|
|
|
|
2021-10-27 08:09:41 -04:00
|
|
|
it_behaves_like "valid runtime", :puma, 13
|
2020-07-08 02:09:13 -04:00
|
|
|
end
|
2021-02-16 10:09:50 -05:00
|
|
|
|
|
|
|
describe ".puma_in_clustered_mode?" do
|
|
|
|
context 'when Puma is set up with workers > 0' do
|
|
|
|
let(:max_workers) { 4 }
|
|
|
|
|
|
|
|
specify { expect(described_class.puma_in_clustered_mode?).to be true }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when Puma is set up with workers = 0' do
|
|
|
|
let(:max_workers) { 0 }
|
|
|
|
|
|
|
|
specify { expect(described_class.puma_in_clustered_mode?).to be false }
|
|
|
|
end
|
|
|
|
end
|
2019-12-22 04:07:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "sidekiq" do
|
|
|
|
let(:sidekiq_type) { double('::Sidekiq') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_const('::Sidekiq', sidekiq_type)
|
|
|
|
allow(sidekiq_type).to receive(:server?).and_return(true)
|
2020-02-06 13:08:54 -05:00
|
|
|
allow(sidekiq_type).to receive(:options).and_return(concurrency: 2)
|
2019-12-22 04:07:51 -05:00
|
|
|
end
|
|
|
|
|
2021-10-20 17:17:26 -04:00
|
|
|
it_behaves_like "valid runtime", :sidekiq, 5
|
2019-12-22 04:07:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "console" do
|
|
|
|
before do
|
2020-02-06 13:08:54 -05:00
|
|
|
stub_const('::Rails::Console', double('::Rails::Console'))
|
2019-12-27 13:08:12 -05:00
|
|
|
end
|
2020-01-15 22:08:47 -05:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
it_behaves_like "valid runtime", :console, 1
|
2019-12-27 13:08:12 -05:00
|
|
|
end
|
|
|
|
|
2020-01-31 07:08:33 -05:00
|
|
|
context "test suite" do
|
2019-12-27 13:08:12 -05:00
|
|
|
before do
|
2020-01-31 07:08:33 -05:00
|
|
|
stub_rails_env('test')
|
2019-12-27 13:08:12 -05:00
|
|
|
end
|
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
it_behaves_like "valid runtime", :test_suite, 1
|
|
|
|
end
|
2019-12-27 13:08:12 -05:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
context "geo log cursor" do
|
|
|
|
before do
|
|
|
|
stub_const('::GeoLogCursorOptionParser', double('::GeoLogCursorOptionParser'))
|
2019-12-22 04:07:51 -05:00
|
|
|
end
|
2020-01-15 22:08:47 -05:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
it_behaves_like "valid runtime", :geo_log_cursor, 1
|
2019-12-22 04:07:51 -05:00
|
|
|
end
|
2020-02-15 01:09:11 -05:00
|
|
|
|
|
|
|
context "rails runner" do
|
|
|
|
before do
|
|
|
|
stub_const('::Rails::Command::RunnerCommand', double('::Rails::Command::RunnerCommand'))
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like "valid runtime", :rails_runner, 1
|
|
|
|
end
|
2019-12-22 04:07:51 -05:00
|
|
|
end
|