Sha256: c483ae781e3d487ee63bce4c3c86341d696bc1abadebd29aff9ea79493b0927f
Contents?: true
Size: 886 Bytes
Versions: 35
Compression:
Stored size: 886 Bytes
Contents
require 'pact/mock_service/server/wait_for_server_up' module Pact module MockService module Server class Spawn class PortUnavailableError < StandardError; end def self.call pidfile, port, ssl = false if pidfile.can_start? if port_available? port pid = fork do yield end pidfile.pid = pid Process.detach(pid) Server::WaitForServerUp.(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) true rescue false ensure server.close if server end end end end end
Version data entries
35 entries across 35 versions & 1 rubygems