Sha256: b4bab6118bd9dcb1487253c9ecacef69115d52d71641114507016128a8cad678

Contents?: true

Size: 903 Bytes

Versions: 25

Compression:

Stored size: 903 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, host, port, ssl = false
          if pidfile.can_start?
            if port_available? host, port
              pid = fork do
                yield
              end
              pidfile.pid = pid
              Process.detach(pid)
              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? host, port
          server = TCPServer.new(host, port)
          true
        rescue
          false
        ensure
          server.close if server
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
pact-mock_service-3.12.3 lib/pact/mock_service/server/spawn.rb
pact-mock_service-3.12.2 lib/pact/mock_service/server/spawn.rb
pact-mock_service-3.12.1 lib/pact/mock_service/server/spawn.rb
pact-mock_service-3.12.0 lib/pact/mock_service/server/spawn.rb
pact-mock_service-3.11.2 lib/pact/mock_service/server/spawn.rb
pact-mock_service-3.11.1 lib/pact/mock_service/server/spawn.rb
pact-mock_service-3.11.0 lib/pact/mock_service/server/spawn.rb
pact-mock_service-3.10.0 lib/pact/mock_service/server/spawn.rb
hs-pact-mock_service-3.9.2 lib/pact/mock_service/server/spawn.rb
pact-mock_service-3.9.1 lib/pact/mock_service/server/spawn.rb
pact-mock_service-3.9.0 lib/pact/mock_service/server/spawn.rb
pact-mock_service-3.8.0 lib/pact/mock_service/server/spawn.rb
pact-mock_service-3.7.0 lib/pact/mock_service/server/spawn.rb
pact-mock_service-3.6.2 lib/pact/mock_service/server/spawn.rb
pact-mock_service-3.6.1 lib/pact/mock_service/server/spawn.rb
pact-mock_service-3.6.0 lib/pact/mock_service/server/spawn.rb
pact-mock_service-3.5.0 lib/pact/mock_service/server/spawn.rb
pact-mock_service-3.4.0 lib/pact/mock_service/server/spawn.rb
pact-mock_service-3.3.1 lib/pact/mock_service/server/spawn.rb
pact-mock_service-3.3.0 lib/pact/mock_service/server/spawn.rb