Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-16 15:06:32 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-16 15:06:32 +0300
commitd2ffc30fd583e86d4122bb5061098f4f3ca7b3f1 (patch)
treecb29c77a3ea49eb8ec732b0e644ed6cfad4770d9 /spec/lib/gitlab/health_checks
parent914ea32e0efca21436220df2c10e1bfbe4ed3da9 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/health_checks')
-rw-r--r--spec/lib/gitlab/health_checks/puma_check_spec.rb65
-rw-r--r--spec/lib/gitlab/health_checks/unicorn_check_spec.rb63
2 files changed, 128 insertions, 0 deletions
diff --git a/spec/lib/gitlab/health_checks/puma_check_spec.rb b/spec/lib/gitlab/health_checks/puma_check_spec.rb
new file mode 100644
index 00000000000..71b6386b174
--- /dev/null
+++ b/spec/lib/gitlab/health_checks/puma_check_spec.rb
@@ -0,0 +1,65 @@
+require 'spec_helper'
+
+describe Gitlab::HealthChecks::PumaCheck do
+ let(:result_class) { Gitlab::HealthChecks::Result }
+ let(:readiness) { described_class.readiness }
+ let(:metrics) { described_class.metrics }
+
+ shared_examples 'with state' do |(state, message)|
+ it "does provide readiness" do
+ expect(readiness).to eq(result_class.new('puma_check', state, message))
+ end
+
+ it "does provide metrics" do
+ expect(metrics).to include(
+ an_object_having_attributes(name: 'puma_check_success', value: state ? 1 : 0))
+ expect(metrics).to include(
+ an_object_having_attributes(name: 'puma_check_latency_seconds', value: be >= 0))
+ end
+ end
+
+ context 'when Puma is not loaded' do
+ before do
+ hide_const('Puma')
+ end
+
+ it "does not provide readiness and metrics" do
+ expect(readiness).to be_nil
+ expect(metrics).to be_nil
+ end
+ end
+
+ context 'when Puma is loaded' do
+ before do
+ stub_const('Puma', Module.new)
+ end
+
+ context 'when stats are missing' do
+ before do
+ expect(Puma).to receive(:stats).and_raise(NoMethodError)
+ end
+
+ it_behaves_like 'with state', [false, 'unexpected Puma check result: 0']
+ end
+
+ context 'for Single mode' do
+ before do
+ expect(Puma).to receive(:stats) do
+ '{}'
+ end
+ end
+
+ it_behaves_like 'with state', true
+ end
+
+ context 'for Cluster mode' do
+ before do
+ expect(Puma).to receive(:stats) do
+ '{"workers":2}'
+ end
+ end
+
+ it_behaves_like 'with state', true
+ end
+ end
+end
diff --git a/spec/lib/gitlab/health_checks/unicorn_check_spec.rb b/spec/lib/gitlab/health_checks/unicorn_check_spec.rb
new file mode 100644
index 00000000000..c02d0c37738
--- /dev/null
+++ b/spec/lib/gitlab/health_checks/unicorn_check_spec.rb
@@ -0,0 +1,63 @@
+require 'spec_helper'
+
+describe Gitlab::HealthChecks::UnicornCheck do
+ let(:result_class) { Gitlab::HealthChecks::Result }
+ let(:readiness) { described_class.readiness }
+ let(:metrics) { described_class.metrics }
+
+ before do
+ described_class.clear_memoization(:http_servers)
+ end
+
+ shared_examples 'with state' do |(state, message)|
+ it "does provide readiness" do
+ expect(readiness).to eq(result_class.new('unicorn_check', state, message))
+ end
+
+ it "does provide metrics" do
+ expect(metrics).to include(
+ an_object_having_attributes(name: 'unicorn_check_success', value: state ? 1 : 0))
+ expect(metrics).to include(
+ an_object_having_attributes(name: 'unicorn_check_latency_seconds', value: be >= 0))
+ end
+ end
+
+ context 'when Unicorn is not loaded' do
+ before do
+ hide_const('Unicorn')
+ end
+
+ it "does not provide readiness and metrics" do
+ expect(readiness).to be_nil
+ expect(metrics).to be_nil
+ end
+ end
+
+ context 'when Unicorn is loaded' do
+ let(:http_server_class) { Struct.new(:worker_processes) }
+
+ before do
+ stub_const('Unicorn::HttpServer', http_server_class)
+ end
+
+ context 'when no servers are running' do
+ it_behaves_like 'with state', [false, 'unexpected Unicorn check result: 0']
+ end
+
+ context 'when servers without workers are running' do
+ before do
+ http_server_class.new(0)
+ end
+
+ it_behaves_like 'with state', [false, 'unexpected Unicorn check result: 0']
+ end
+
+ context 'when servers with workers are running' do
+ before do
+ http_server_class.new(1)
+ end
+
+ it_behaves_like 'with state', true
+ end
+ end
+end