From d0698978ba0c61716da246a6b1fadfab1ee6d33f Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto <brodock@gmail.com> Date: Tue, 27 Jun 2017 17:41:58 +0200 Subject: [PATCH 1/4] Make the SimpleExecutor rescue exceptions in the executing Checks --- lib/system_check/simple_executor.rb | 2 ++ spec/lib/system_check/simple_executor_spec.rb | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/system_check/simple_executor.rb b/lib/system_check/simple_executor.rb index dc2d4643a0114..e5986612908e9 100644 --- a/lib/system_check/simple_executor.rb +++ b/lib/system_check/simple_executor.rb @@ -75,6 +75,8 @@ def run_check(check_klass) check.show_error end + rescue StandardError => e + $stdout.puts "Exception: #{e.message}".color(:red) end private diff --git a/spec/lib/system_check/simple_executor_spec.rb b/spec/lib/system_check/simple_executor_spec.rb index a5c6170cd7de7..5de768d99ed16 100644 --- a/spec/lib/system_check/simple_executor_spec.rb +++ b/spec/lib/system_check/simple_executor_spec.rb @@ -75,6 +75,15 @@ def show_error end end + class BugousCheck < SystemCheck::BaseCheck + CustomError = Class.new(StandardError) + set_name 'my bugous check' + + def check? + raise CustomError, 'omg' + end + end + describe '#component' do it 'returns stored component name' do expect(subject.component).to eq('Test') @@ -138,14 +147,14 @@ def show_error context 'when check pass' do it 'prints yes' do expect_any_instance_of(SimpleCheck).to receive(:check?).and_call_original - expect { subject.run_check(SimpleCheck) }.to output(/ \.\.\. yes/).to_stdout + expect { subject.run_check(SimpleCheck) }.to output(/ \.\.\. \e\[32myes/).to_stdout end end context 'when check fails' do it 'prints no' do expect_any_instance_of(OtherCheck).to receive(:check?).and_call_original - expect { subject.run_check(OtherCheck) }.to output(/ \.\.\. no/).to_stdout + expect { subject.run_check(OtherCheck) }.to output(/ \.\.\. \e\[31mno/).to_stdout end it 'displays error message from #show_error' do @@ -219,5 +228,11 @@ def show_error end end end + + context 'when there is an exception' do + it 'rescues the exception' do + expect{ subject.run_check(BugousCheck) }.not_to raise_exception + end + end end end -- GitLab From 74660e2f7c4bba6e066899f66891d6f867636f8c Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto <brodock@gmail.com> Date: Tue, 27 Jun 2017 17:42:22 +0200 Subject: [PATCH 2/4] Fix elasticsearch check logic --- lib/system_check/app/elasticsearch_check.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/system_check/app/elasticsearch_check.rb b/lib/system_check/app/elasticsearch_check.rb index cff7cc6e5120c..06930b1d5a5e3 100644 --- a/lib/system_check/app/elasticsearch_check.rb +++ b/lib/system_check/app/elasticsearch_check.rb @@ -18,7 +18,13 @@ def skip? end def check? - current_version.major == 5 && (1..3).cover?(version.minor) + self.class.current_version.major == 5 && (1..3).cover?(self.class.current_version.minor) + end + + def show_error + for_more_information( + 'doc/integration/elasticsearch.md' + ) end end end -- GitLab From d9a48ea115f27c463ec1b42fcd4357e14784bdba Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto <brodock@gmail.com> Date: Tue, 27 Jun 2017 17:49:37 +0200 Subject: [PATCH 3/4] Changelog --- changelogs/unreleased-ee/2757-fix-elasticsearch-check.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelogs/unreleased-ee/2757-fix-elasticsearch-check.yml diff --git a/changelogs/unreleased-ee/2757-fix-elasticsearch-check.yml b/changelogs/unreleased-ee/2757-fix-elasticsearch-check.yml new file mode 100644 index 0000000000000..0fbce7dc4ab12 --- /dev/null +++ b/changelogs/unreleased-ee/2757-fix-elasticsearch-check.yml @@ -0,0 +1,4 @@ +--- +title: 'Fix GitLab check: Problem with Elastic Search' +merge_request: 2278 +author: -- GitLab From 97db97f19d157cd7ceb179f40dea68e3364816d1 Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto <brodock@gmail.com> Date: Tue, 27 Jun 2017 20:18:23 +0200 Subject: [PATCH 4/4] Disable rainbow during SimpleExecutor specs to have consistence --- spec/lib/system_check/simple_executor_spec.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/spec/lib/system_check/simple_executor_spec.rb b/spec/lib/system_check/simple_executor_spec.rb index 5de768d99ed16..795f11ee1f8b6 100644 --- a/spec/lib/system_check/simple_executor_spec.rb +++ b/spec/lib/system_check/simple_executor_spec.rb @@ -84,6 +84,15 @@ def check? end end + before do + @rainbow = Rainbow.enabled + Rainbow.enabled = false + end + + after do + Rainbow.enabled = @rainbow + end + describe '#component' do it 'returns stored component name' do expect(subject.component).to eq('Test') @@ -147,14 +156,14 @@ def check? context 'when check pass' do it 'prints yes' do expect_any_instance_of(SimpleCheck).to receive(:check?).and_call_original - expect { subject.run_check(SimpleCheck) }.to output(/ \.\.\. \e\[32myes/).to_stdout + expect { subject.run_check(SimpleCheck) }.to output(/ \.\.\. yes/).to_stdout end end context 'when check fails' do it 'prints no' do expect_any_instance_of(OtherCheck).to receive(:check?).and_call_original - expect { subject.run_check(OtherCheck) }.to output(/ \.\.\. \e\[31mno/).to_stdout + expect { subject.run_check(OtherCheck) }.to output(/ \.\.\. no/).to_stdout end it 'displays error message from #show_error' do -- GitLab