Skip to content

Commit

Permalink
fix: add missing host argument to server spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Mar 7, 2019
1 parent 3b10bbc commit ee5cf90
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions lib/pact/mock_service/server/spawn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ class Spawn

class PortUnavailableError < StandardError; end

def self.call pidfile, port, ssl = false
def self.call pidfile, host, port, ssl = false
if pidfile.can_start?
if port_available? port
if port_available? host, port
pid = fork do
yield
end
pidfile.pid = pid
Process.detach(pid)
Server::WaitForServerUp.(port, {ssl: ssl})
Server::WaitForServerUp.(host, port, {ssl: ssl})
pidfile.write
else
raise PortUnavailableError.new("ERROR: Port #{port} already in use.")
end
end
end

def self.port_available? port
server = TCPServer.new('127.0.0.1', port)
def self.port_available? host, port
server = TCPServer.new(host, port)
true
rescue
false
Expand Down
10 changes: 5 additions & 5 deletions lib/pact/mock_service/server/wait_for_server_up.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ module MockService
module Server
class WaitForServerUp

def self.call(port, options = {ssl: false})
def self.call(host, port, options = {ssl: false})
tries = 0
responsive = false
while !(responsive = responsive?(port, options)) && tries < 100
while !(responsive = responsive?(host, port, options)) && tries < 100
tries += 1
sleep 1
end
raise "Timed out waiting for server to start up on port #{port}" if !responsive
end

def self.responsive? port, options
http = Net::HTTP.new('localhost', port)
def self.responsive? host, port, options
http = Net::HTTP.new(host, port)
if options[:ssl]
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
Expand All @@ -27,7 +27,7 @@ def self.responsive? port, options
scheme = 'http'
end
http.start {
request = Net::HTTP::Get.new "#{scheme}://localhost:#{port}/"
request = Net::HTTP::Get.new "#{scheme}://#{host}:#{port}/"
request['X-Pact-Mock-Service'] = true
response = http.request request
response.code == '200'
Expand Down
2 changes: 1 addition & 1 deletion spec/support/integration_spec_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def start_control port, options = ''
end

def wait_until_server_started port, ssl = false
Pact::MockService::Server::WaitForServerUp.(port, {ssl: ssl})
Pact::MockService::Server::WaitForServerUp.("localhost", port, {ssl: ssl})
end

def kill_server pid
Expand Down

0 comments on commit ee5cf90

Please sign in to comment.