Commit 79242441 authored by Terence Lee's avatar Terence Lee

debug output for running app, connect to server after nginx has started,

network retry incase nginx hasn't bound to the port yet
parent cf80709c
......@@ -3,4 +3,5 @@ source "https://rubygems.org"
group :development do
gem "docker-api"
gem "rspec"
gem "concurrent-ruby"
end
GEM
remote: https://rubygems.org/
specs:
concurrent-ruby (0.8.0)
ref (~> 1.0, >= 1.0.5)
diff-lcs (1.2.5)
docker-api (1.21.4)
excon (>= 0.38.0)
json
excon (0.45.3)
json (1.8.2)
ref (1.0.5)
rspec (3.2.0)
rspec-core (~> 3.2.0)
rspec-expectations (~> 3.2.0)
......@@ -25,6 +28,7 @@ PLATFORMS
ruby
DEPENDENCIES
concurrent-ruby
docker-api
rspec
......
......@@ -3,6 +3,7 @@ require "net/http"
require "fileutils"
require "json"
require "docker"
require "concurrent/atomic/count_down_latch"
require_relative "path_helper"
class AppRunner
......@@ -29,21 +30,34 @@ class AppRunner
end
def run
#@container.tap(&:start).attach { |stream, chunk| puts "#{stream}: #{chunk}" }
@container.start
sleep(1)
yield(@container)
latch = Concurrent::CountDownLatch.new(1)
run_thread = Thread.new {
latch.wait(0.5)
yield(@container)
}
container_thread = Thread.new {
@container.tap(&:start).attach do |stream, chunk|
puts "#{stream}: #{chunk}" if @debug
latch.count_down if chunk.include?("Starting nginx...")
end
}
run_thread.join
@container.stop
container_thread.join
end
def get(path)
def get(path, max_retries = 5)
response = nil
run do
uri = URI("http://#{HOST_IP}:#{HOST_PORT}/#{path}")
response = Net::HTTP.get_response(uri)
network_retry(max_retries) do
uri = URI("http://#{HOST_IP}:#{HOST_PORT}/#{path}")
response = Net::HTTP.get_response(uri)
end
end
return response
response
end
def destroy
......@@ -54,6 +68,17 @@ class AppRunner
end
private
def network_retry(max_retries, retry_count = 0)
yield
rescue Errno::ECONNRESET, EOFError
if retry_count < max_retries
puts "Retry Count: #{retry_count}" if @debug
sleep(0.01 * retry_count)
retry_count += 1
retry
end
end
def build_image(fixture)
image = nil
......
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