From ca1c71ea68c4baff2560168eda7184c5469062b8 Mon Sep 17 00:00:00 2001 From: Karl Southern Date: Thu, 15 Sep 2016 21:32:34 +0100 Subject: [PATCH] Travis --- spec/jdbc_spec_helper.rb | 47 ++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/spec/jdbc_spec_helper.rb b/spec/jdbc_spec_helper.rb index 7a40111..7ce2e6e 100644 --- a/spec/jdbc_spec_helper.rb +++ b/spec/jdbc_spec_helper.rb @@ -4,6 +4,32 @@ require 'stud/temporary' require 'java' require 'securerandom' +RSpec.configure do |c| + + def start_service(name) + cmd = "sudo /etc/init.d/#{name}* stop" + + `which systemctl` + if $?.success? + cmd = "sudo systemctl start #{name}" + end + + `#{cmd}` + end + + def stop_service(name) + cmd = "sudo /etc/init.d/#{name}* stop" + + `which systemctl` + if $?.success? + cmd = "sudo systemctl stop #{name}" + end + + `#{cmd}` + end + +end + RSpec.shared_context 'rspec setup' do it 'ensure jar is available' do expect(ENV[jdbc_jar_env]).not_to be_nil, "#{jdbc_jar_env} not defined, required to run tests" @@ -124,28 +150,21 @@ RSpec.shared_context 'when outputting messages' do # Check that everything is fine right now expect { p.multi_receive([event]) }.not_to raise_error - start_stop_cmd = 'sudo /etc/init.d/%s* %s' - - `which systemctl` - if $?.success? - start_stop_cmd = 'sudo systemctl %s %s' - end - - cmd = start_stop_cmd % { action: 'stop', service: systemd_database_service } - `#{cmd}` + stop_service(systemd_database_service) # Start a thread to restart the service after the fact. - t = Thread.new(systemd_database_service) { |start_stop_cmd, systemd_database_service| + t = Thread.new(systemd_database_service) { |systemd_database_service| sleep 20 - - cmd = start_stop_cmd % { action: 'start', service: systemd_database_service } - `#{cmd}` + + start_service(systemd_database_service) } - t.run + t.run + expect(logger).to receive(:warn).at_least(:once).with(/JDBC - Exception. Retrying/, Hash) expect { p.multi_receive([event]) }.to_not raise_error + # Wait for the thread to finish t.join end end