2017-04-07 06:27:15 -04:00
|
|
|
shared_context 'simple_check' do |metrics_prefix, check_name, success_result|
|
|
|
|
describe '#metrics' do
|
|
|
|
subject { described_class.metrics }
|
|
|
|
context 'Check is passing' do
|
|
|
|
before do
|
|
|
|
allow(described_class).to receive(:check).and_return success_result
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to include(have_attributes(name: "#{metrics_prefix}_success", value: 1)) }
|
|
|
|
it { is_expected.to include(have_attributes(name: "#{metrics_prefix}_timeout", value: 0)) }
|
2017-07-12 08:48:46 -04:00
|
|
|
it { is_expected.to include(have_attributes(name: "#{metrics_prefix}_latency_seconds", value: be >= 0)) }
|
2017-04-07 06:27:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'Check is misbehaving' do
|
|
|
|
before do
|
|
|
|
allow(described_class).to receive(:check).and_return 'error!'
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to include(have_attributes(name: "#{metrics_prefix}_success", value: 0)) }
|
|
|
|
it { is_expected.to include(have_attributes(name: "#{metrics_prefix}_timeout", value: 0)) }
|
2017-07-12 08:48:46 -04:00
|
|
|
it { is_expected.to include(have_attributes(name: "#{metrics_prefix}_latency_seconds", value: be >= 0)) }
|
2017-04-07 06:27:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'Check is timeouting' do
|
|
|
|
before do
|
|
|
|
allow(described_class).to receive(:check).and_return Timeout::Error.new
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to include(have_attributes(name: "#{metrics_prefix}_success", value: 0)) }
|
|
|
|
it { is_expected.to include(have_attributes(name: "#{metrics_prefix}_timeout", value: 1)) }
|
2017-07-12 08:48:46 -04:00
|
|
|
it { is_expected.to include(have_attributes(name: "#{metrics_prefix}_latency_seconds", value: be >= 0)) }
|
2017-04-07 06:27:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#readiness' do
|
|
|
|
subject { described_class.readiness }
|
|
|
|
context 'Check returns ok' do
|
|
|
|
before do
|
|
|
|
allow(described_class).to receive(:check).and_return success_result
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to have_attributes(success: true) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'Check is misbehaving' do
|
|
|
|
before do
|
|
|
|
allow(described_class).to receive(:check).and_return 'error!'
|
|
|
|
end
|
|
|
|
|
2017-07-10 23:35:47 -04:00
|
|
|
it { is_expected.to have_attributes(success: false, message: "unexpected #{described_class.human_name} check result: error!") }
|
2017-04-07 06:27:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'Check is timeouting' do
|
|
|
|
before do
|
|
|
|
allow(described_class).to receive(:check ).and_return Timeout::Error.new
|
|
|
|
end
|
|
|
|
|
2017-07-10 23:35:47 -04:00
|
|
|
it { is_expected.to have_attributes(success: false, message: "#{described_class.human_name} check timed out") }
|
2017-04-07 06:27:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#liveness' do
|
|
|
|
subject { described_class.readiness }
|
|
|
|
it { is_expected.to eq(Gitlab::HealthChecks::Result.new(true)) }
|
|
|
|
end
|
|
|
|
end
|