2021-01-19 16:10:45 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'validate puma' do
|
2021-02-11 07:08:52 -05:00
|
|
|
include RakeHelpers
|
|
|
|
|
2021-01-19 16:10:45 -05:00
|
|
|
subject do
|
|
|
|
load Rails.root.join('config/initializers/validate_puma.rb')
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_const('Puma', double)
|
|
|
|
allow(Gitlab::Runtime).to receive(:puma?).and_return(true)
|
|
|
|
allow(Puma).to receive_message_chain(:cli_config, :options).and_return(workers: workers)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for .com' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab).to receive(:com?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when worker count is 0' do
|
|
|
|
let(:workers) { 0 }
|
|
|
|
|
2021-02-11 07:08:52 -05:00
|
|
|
specify { expect { subject }.to raise_error(String) }
|
2021-01-19 16:10:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when worker count is > 0' do
|
|
|
|
let(:workers) { 2 }
|
|
|
|
|
2021-02-11 07:08:52 -05:00
|
|
|
specify { expect { subject }.not_to raise_error }
|
2021-01-19 16:10:45 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for other environments' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab).to receive(:com?).and_return(false)
|
2021-02-11 07:08:52 -05:00
|
|
|
|
|
|
|
allow(main_object).to receive(:warn)
|
2021-01-19 16:10:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when worker count is 0' do
|
|
|
|
let(:workers) { 0 }
|
|
|
|
|
2021-02-11 07:08:52 -05:00
|
|
|
specify { expect { subject }.not_to raise_error }
|
2021-01-19 16:10:45 -05:00
|
|
|
|
2021-02-11 07:08:52 -05:00
|
|
|
it 'warns about running Puma in a Single mode' do
|
|
|
|
expect(main_object).to receive(:warn) do |warning|
|
|
|
|
expect(warning).to include('https://gitlab.com/groups/gitlab-org/-/epics/5303')
|
|
|
|
end
|
2021-01-19 16:10:45 -05:00
|
|
|
|
2021-02-11 07:08:52 -05:00
|
|
|
subject
|
2021-01-19 16:10:45 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when worker count is > 0' do
|
|
|
|
let(:workers) { 2 }
|
|
|
|
|
2021-02-11 07:08:52 -05:00
|
|
|
specify { expect { subject }.not_to raise_error }
|
2021-01-19 16:10:45 -05:00
|
|
|
|
2021-02-11 07:08:52 -05:00
|
|
|
it 'does not issue a warning' do
|
|
|
|
expect(main_object).not_to receive(:warn)
|
2021-01-19 16:10:45 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|