diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-22 09:07:51 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-22 09:07:51 +0000 |
commit | 3ad11f24ca52d42694a8ce920a87ead6085d3f85 (patch) | |
tree | d5b664aafa7c2b65f470a700431d336d908c0ebc /spec | |
parent | 62fcb9ffa9e40db6f34e7dd0d36804d73ef01435 (diff) | |
download | gitlab-ce-3ad11f24ca52d42694a8ce920a87ead6085d3f85.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/initializers/database_config_spec.rb | 1 | ||||
-rw-r--r-- | spec/lib/gitlab/gitaly_client_spec.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/gpg_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/health_checks/puma_check_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/health_checks/unicorn_check_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/highlight_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/metrics/samplers/influx_sampler_spec.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/runtime_spec.rb | 101 | ||||
-rw-r--r-- | spec/lib/prometheus/pid_provider_spec.rb | 18 | ||||
-rw-r--r-- | spec/services/git/branch_push_service_spec.rb | 2 | ||||
-rw-r--r-- | spec/support/redis/redis_shared_examples.rb | 4 |
11 files changed, 119 insertions, 23 deletions
diff --git a/spec/initializers/database_config_spec.rb b/spec/initializers/database_config_spec.rb index a5a074f5884..9200a625b38 100644 --- a/spec/initializers/database_config_spec.rb +++ b/spec/initializers/database_config_spec.rb @@ -16,6 +16,7 @@ describe 'Database config initializer' do let(:puma_options) { { max_threads: 8 } } before do + allow(Gitlab::Runtime).to receive(:puma?).and_return(true) stub_const("Puma", puma) allow(puma).to receive_message_chain(:cli_config, :options).and_return(puma_options) end diff --git a/spec/lib/gitlab/gitaly_client_spec.rb b/spec/lib/gitlab/gitaly_client_spec.rb index 4b69b4734f1..0d9719a5663 100644 --- a/spec/lib/gitlab/gitaly_client_spec.rb +++ b/spec/lib/gitlab/gitaly_client_spec.rb @@ -26,7 +26,7 @@ describe Gitlab::GitalyClient do context 'running in Unicorn' do before do - stub_const('Unicorn', 1) + allow(Gitlab::Runtime).to receive(:unicorn?).and_return(true) end it { expect(subject.long_timeout).to eq(55) } @@ -34,7 +34,7 @@ describe Gitlab::GitalyClient do context 'running in Puma' do before do - stub_const('Puma', 1) + allow(Gitlab::Runtime).to receive(:puma?).and_return(true) end it { expect(subject.long_timeout).to eq(55) } diff --git a/spec/lib/gitlab/gpg_spec.rb b/spec/lib/gitlab/gpg_spec.rb index 8600ef223c6..27a3010eeed 100644 --- a/spec/lib/gitlab/gpg_spec.rb +++ b/spec/lib/gitlab/gpg_spec.rb @@ -236,7 +236,7 @@ describe Gitlab::Gpg do context 'when running in Sidekiq' do before do - allow(Sidekiq).to receive(:server?).and_return(true) + allow(Gitlab::Runtime).to receive(:sidekiq?).and_return(true) end it_behaves_like 'multiple deletion attempts of the tmp-dir', described_class::BG_CLEANUP_RUNTIME_S diff --git a/spec/lib/gitlab/health_checks/puma_check_spec.rb b/spec/lib/gitlab/health_checks/puma_check_spec.rb index dd052a4dd2c..93ef81978a8 100644 --- a/spec/lib/gitlab/health_checks/puma_check_spec.rb +++ b/spec/lib/gitlab/health_checks/puma_check_spec.rb @@ -22,6 +22,7 @@ describe Gitlab::HealthChecks::PumaCheck do context 'when Puma is not loaded' do before do + allow(Gitlab::Runtime).to receive(:puma?).and_return(false) hide_const('Puma') end @@ -33,6 +34,7 @@ describe Gitlab::HealthChecks::PumaCheck do context 'when Puma is loaded' do before do + allow(Gitlab::Runtime).to receive(:puma?).and_return(true) stub_const('Puma', Module.new) end diff --git a/spec/lib/gitlab/health_checks/unicorn_check_spec.rb b/spec/lib/gitlab/health_checks/unicorn_check_spec.rb index 931b61cb168..7c57b6f1ca5 100644 --- a/spec/lib/gitlab/health_checks/unicorn_check_spec.rb +++ b/spec/lib/gitlab/health_checks/unicorn_check_spec.rb @@ -26,6 +26,7 @@ describe Gitlab::HealthChecks::UnicornCheck do context 'when Unicorn is not loaded' do before do + allow(Gitlab::Runtime).to receive(:unicorn?).and_return(false) hide_const('Unicorn') end @@ -39,6 +40,7 @@ describe Gitlab::HealthChecks::UnicornCheck do let(:http_server_class) { Struct.new(:worker_processes) } before do + allow(Gitlab::Runtime).to receive(:unicorn?).and_return(true) stub_const('Unicorn::HttpServer', http_server_class) end diff --git a/spec/lib/gitlab/highlight_spec.rb b/spec/lib/gitlab/highlight_spec.rb index 5a45d724b83..2140cbae488 100644 --- a/spec/lib/gitlab/highlight_spec.rb +++ b/spec/lib/gitlab/highlight_spec.rb @@ -111,7 +111,7 @@ describe Gitlab::Highlight do end it 'utilizes longer timeout for sidekiq' do - allow(Sidekiq).to receive(:server?).and_return(true) + allow(Gitlab::Runtime).to receive(:sidekiq?).and_return(true) expect(Timeout).to receive(:timeout).with(described_class::TIMEOUT_BACKGROUND).and_call_original subject.highlight("Content") diff --git a/spec/lib/gitlab/metrics/samplers/influx_sampler_spec.rb b/spec/lib/gitlab/metrics/samplers/influx_sampler_spec.rb index 2d4b27a6ac1..939c057c342 100644 --- a/spec/lib/gitlab/metrics/samplers/influx_sampler_spec.rb +++ b/spec/lib/gitlab/metrics/samplers/influx_sampler_spec.rb @@ -63,7 +63,7 @@ describe Gitlab::Metrics::Samplers::InfluxSampler do describe '#add_metric' do it 'prefixes the series name for a Rails process' do - expect(sampler).to receive(:sidekiq?).and_return(false) + expect(Gitlab::Runtime).to receive(:sidekiq?).and_return(false) expect(Gitlab::Metrics::Metric).to receive(:new) .with('rails_cats', { value: 10 }, {}) @@ -73,7 +73,7 @@ describe Gitlab::Metrics::Samplers::InfluxSampler do end it 'prefixes the series name for a Sidekiq process' do - expect(sampler).to receive(:sidekiq?).and_return(true) + expect(Gitlab::Runtime).to receive(:sidekiq?).and_return(true) expect(Gitlab::Metrics::Metric).to receive(:new) .with('sidekiq_cats', { value: 10 }, {}) diff --git a/spec/lib/gitlab/runtime_spec.rb b/spec/lib/gitlab/runtime_spec.rb new file mode 100644 index 00000000000..ff8b383ba45 --- /dev/null +++ b/spec/lib/gitlab/runtime_spec.rb @@ -0,0 +1,101 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Runtime do + 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 + + context "puma" do + let(:puma_type) { double('::Puma') } + + before do + stub_const('::Puma', puma_type) + end + + it "identifies itself" do + expect(subject.identify).to eq(:puma) + expect(subject.puma?).to be(true) + end + + it "does not identify as others" do + expect(subject.unicorn?).to be(false) + expect(subject.sidekiq?).to be(false) + expect(subject.console?).to be(false) + end + end + + context "unicorn" do + let(:unicorn_type) { Module.new } + let(:unicorn_server_type) { Class.new } + + before do + stub_const('::Unicorn', unicorn_type) + stub_const('::Unicorn::HttpServer', unicorn_server_type) + end + + it "identifies itself" do + expect(subject.identify).to eq(:unicorn) + expect(subject.unicorn?).to be(true) + end + + it "does not identify as others" do + expect(subject.puma?).to be(false) + expect(subject.sidekiq?).to be(false) + expect(subject.console?).to be(false) + end + 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) + end + + it "identifies itself" do + expect(subject.identify).to eq(:sidekiq) + expect(subject.sidekiq?).to be(true) + end + + it "does not identify as others" do + expect(subject.unicorn?).to be(false) + expect(subject.puma?).to be(false) + expect(subject.console?).to be(false) + end + end + + context "console" do + let(:console_type) { double('::Rails::Console') } + + before do + stub_const('::Rails::Console', console_type) + end + + it "identifies itself" do + expect(subject.identify).to eq(:console) + expect(subject.console?).to be(true) + end + + it "does not identify as others" do + expect(subject.unicorn?).to be(false) + expect(subject.sidekiq?).to be(false) + expect(subject.puma?).to be(false) + end + end +end diff --git a/spec/lib/prometheus/pid_provider_spec.rb b/spec/lib/prometheus/pid_provider_spec.rb index 6fdc11b14c4..5a17f25f144 100644 --- a/spec/lib/prometheus/pid_provider_spec.rb +++ b/spec/lib/prometheus/pid_provider_spec.rb @@ -6,16 +6,13 @@ describe Prometheus::PidProvider do describe '.worker_id' do subject { described_class.worker_id } - let(:sidekiq_module) { Module.new } - before do - allow(sidekiq_module).to receive(:server?).and_return(false) - stub_const('Sidekiq', sidekiq_module) + allow(Gitlab::Runtime).to receive(:sidekiq?).and_return(false) end context 'when running in Sidekiq server mode' do before do - expect(Sidekiq).to receive(:server?).and_return(true) + allow(Gitlab::Runtime).to receive(:sidekiq?).and_return(true) end context 'in a clustered setup' do @@ -33,8 +30,7 @@ describe Prometheus::PidProvider do context 'when running in Unicorn mode' do before do - stub_const('Unicorn::Worker', Class.new) - hide_const('Puma') + allow(Gitlab::Runtime).to receive(:unicorn?).and_return(true) expect(described_class).to receive(:process_name) .at_least(:once) @@ -94,8 +90,7 @@ describe Prometheus::PidProvider do context 'when running in Puma mode' do before do - stub_const('Puma', Module.new) - hide_const('Unicorn::Worker') + allow(Gitlab::Runtime).to receive(:puma?).and_return(true) expect(described_class).to receive(:process_name) .at_least(:once) @@ -116,11 +111,6 @@ describe Prometheus::PidProvider do end context 'when running in unknown mode' do - before do - hide_const('Puma') - hide_const('Unicorn::Worker') - end - it { is_expected.to eq "process_#{Process.pid}" } end end diff --git a/spec/services/git/branch_push_service_spec.rb b/spec/services/git/branch_push_service_spec.rb index 19d7b84a3ce..e7f005cff0b 100644 --- a/spec/services/git/branch_push_service_spec.rb +++ b/spec/services/git/branch_push_service_spec.rb @@ -108,7 +108,7 @@ describe Git::BranchPushService, services: true do end it 'reports an error' do - allow(Sidekiq).to receive(:server?).and_return(true) + allow(Gitlab::Runtime).to receive(:sidekiq?).and_return(true) expect(Sidekiq.logger).to receive(:warn) expect { subject }.not_to change { Ci::Pipeline.count } diff --git a/spec/support/redis/redis_shared_examples.rb b/spec/support/redis/redis_shared_examples.rb index 97a23f02b3e..e079c32d6ae 100644 --- a/spec/support/redis/redis_shared_examples.rb +++ b/spec/support/redis/redis_shared_examples.rb @@ -118,7 +118,7 @@ RSpec.shared_examples "redis_shared_examples" do context 'when running not on sidekiq workers' do before do - allow(Sidekiq).to receive(:server?).and_return(false) + allow(Gitlab::Runtime).to receive(:sidekiq?).and_return(false) end it 'instantiates a connection pool with size 5' do @@ -130,7 +130,7 @@ RSpec.shared_examples "redis_shared_examples" do context 'when running on sidekiq workers' do before do - allow(Sidekiq).to receive(:server?).and_return(true) + allow(Gitlab::Runtime).to receive(:sidekiq?).and_return(true) allow(Sidekiq).to receive(:options).and_return({ concurrency: 18 }) end |