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
class Secondary
include QA::Scenario::Actable
WAIT_FOR_SERVICES_SECS = 120
def initialize
@address = QA::Runtime::Scenario.geo_secondary_address
@name = QA::Runtime::Scenario.geo_secondary_name
......@@ -135,23 +137,13 @@ module QA
def wait_for_services
puts 'Waiting until secondary node services are ready ...'
Time.new.tap do |start|
while Time.new - start < 120
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
elapsed = try_for(WAIT_FOR_SERVICES_SECS) do |elapsed|
break elapsed if host_ready?
end
raise "Secondary node did not start correctly in #{Time.now - start} seconds!"
end
puts "\nSecondary ready after #{elapsed} seconds."
rescue TryForExceeded
raise "Secondary node did not start correctly after #{WAIT_FOR_SERVICES_SECS} seconds!"
end
def authorize
......@@ -169,7 +161,33 @@ module QA
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?
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'))
JSON.parse(body)['status'] == 'ok'
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