Commit e37d18ed authored by Ash McKenzie's avatar Ash McKenzie

Refactor wait_for_services to aim for more SRP

parent 2fa30478
...@@ -102,6 +102,8 @@ module QA ...@@ -102,6 +102,8 @@ module QA
class Secondary class Secondary
include QA::Scenario::Actable include QA::Scenario::Actable
WAIT_FOR_SERVICES_SECS = 120
def initialize def initialize
@address = QA::Runtime::Scenario.geo_secondary_address @address = QA::Runtime::Scenario.geo_secondary_address
@name = QA::Runtime::Scenario.geo_secondary_name @name = QA::Runtime::Scenario.geo_secondary_name
...@@ -135,23 +137,13 @@ module QA ...@@ -135,23 +137,13 @@ module QA
def wait_for_services def wait_for_services
puts 'Waiting until secondary node services are ready ...' puts 'Waiting until secondary node services are ready ...'
Time.new.tap do |start| elapsed = try_for(WAIT_FOR_SERVICES_SECS) do |elapsed|
while Time.new - start < 120 break elapsed if host_ready?
begin
if host_ready?
return puts "\nSecondary ready after #{Time.now - start} seconds." # rubocop:disable Cop/AvoidReturnFromBlocks
else
print '.'
end
rescue StandardError
print 'e'
end
sleep 1
end end
raise "Secondary node did not start correctly in #{Time.now - start} seconds!" puts "\nSecondary ready after #{elapsed} seconds."
end rescue TryForExceeded
raise "Secondary node did not start correctly after #{WAIT_FOR_SERVICES_SECS} seconds!"
end end
def authorize def authorize
...@@ -169,7 +161,33 @@ module QA ...@@ -169,7 +161,33 @@ module QA
private private
TryForExceeded = Class.new(StandardError)
def try_for(secs)
start = Time.new
loop do
elapsed = (Time.new - start).round(2)
break elapsed if elapsed >= secs
yield elapsed
sleep 1
end
raise TryForExceeded
end
def host_ready? def host_ready?
return true if host_status_ok?
print '.'
false
rescue StandardError
print 'e'
false
end
def host_status_ok?
body = Net::HTTP.get(URI.join(@address, '/-/readiness')) body = Net::HTTP.get(URI.join(@address, '/-/readiness'))
JSON.parse(body)['status'] == 'ok' JSON.parse(body)['status'] == 'ok'
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment