diff options
author | Stan Hu <stanhu@gmail.com> | 2019-07-09 21:34:03 +0000 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-07-09 21:34:03 +0000 |
commit | 306c8caa2c7ac075d10f087a888017e65ea2ad7e (patch) | |
tree | 8ec776228baccfaffd4dea0a035617f9824443b0 /spec | |
parent | 109956a65b873a245b26915eb5f48f40942e4453 (diff) | |
parent | 580368c09b5f9f243b5ec8e271359d6a4ac8c398 (diff) | |
download | gitlab-ce-306c8caa2c7ac075d10f087a888017e65ea2ad7e.tar.gz |
Merge branch 'fix-unicorn-sampler-workers-count' into 'master'
Make unicorn_workers to return meaningful results
Closes #63659
See merge request gitlab-org/gitlab-ce!30506
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/metrics/samplers/unicorn_sampler_spec.rb | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/spec/lib/gitlab/metrics/samplers/unicorn_sampler_spec.rb b/spec/lib/gitlab/metrics/samplers/unicorn_sampler_spec.rb index 090e456644f..4b697b2ba0f 100644 --- a/spec/lib/gitlab/metrics/samplers/unicorn_sampler_spec.rb +++ b/spec/lib/gitlab/metrics/samplers/unicorn_sampler_spec.rb @@ -4,7 +4,7 @@ describe Gitlab::Metrics::Samplers::UnicornSampler do subject { described_class.new(1.second) } describe '#sample' do - let(:unicorn) { double('unicorn') } + let(:unicorn) { Module.new } let(:raindrops) { double('raindrops') } let(:stats) { double('stats') } @@ -78,19 +78,32 @@ describe Gitlab::Metrics::Samplers::UnicornSampler do end end - context 'additional metrics' do - let(:unicorn_workers) { 2 } - + context 'unicorn workers' do before do - allow(unicorn).to receive(:listener_names).and_return([""]) - allow(::Gitlab::Metrics::System).to receive(:cpu_time).and_return(3.14) - allow(subject).to receive(:unicorn_workers_count).and_return(unicorn_workers) + allow(unicorn).to receive(:listener_names).and_return([]) end - it "sets additional metrics" do - expect(subject.metrics[:unicorn_workers]).to receive(:set).with({}, unicorn_workers) + context 'without http server' do + it "does set unicorn_workers to 0" do + expect(subject.metrics[:unicorn_workers]).to receive(:set).with({}, 0) - subject.sample + subject.sample + end + end + + context 'with http server' do + let(:http_server_class) { Struct.new(:worker_processes) } + let!(:http_server) { http_server_class.new(5) } + + before do + stub_const('Unicorn::HttpServer', http_server_class) + end + + it "sets additional metrics" do + expect(subject.metrics[:unicorn_workers]).to receive(:set).with({}, 5) + + subject.sample + end end end end |