Sha256: 353ab1ae289695798f746e377c0ba9a02846f422062a018c467f5cf5c3d1c319

Contents?: true

Size: 861 Bytes

Versions: 21

Compression:

Stored size: 861 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
          if pidfile.can_start?
            if port_available? port
              pid = fork do
                yield
              end
              pidfile.pid = pid
              Process.detach(pid)
              Server::WaitForServerUp.(port)
              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

21 entries across 21 versions & 1 rubygems

Version Path
pact-mock_service-0.10.1 lib/pact/mock_service/server/spawn.rb
pact-mock_service-0.10.0 lib/pact/mock_service/server/spawn.rb
pact-mock_service-0.9.0 lib/pact/mock_service/server/spawn.rb
pact-mock_service-0.8.2 lib/pact/mock_service/server/spawn.rb
pact-mock_service-0.8.1 lib/pact/mock_service/server/spawn.rb
pact-mock_service-0.8.0 lib/pact/mock_service/server/spawn.rb
pact-mock_service-0.7.2 lib/pact/mock_service/server/spawn.rb
pact-mock_service-0.7.1 lib/pact/mock_service/server/spawn.rb
pact-mock_service-0.7.0 lib/pact/mock_service/server/spawn.rb
pact-mock_service-0.6.0 lib/pact/mock_service/server/spawn.rb
pact-mock_service-0.5.5 lib/pact/mock_service/server/spawn.rb
pact-mock_service-0.5.4 lib/pact/mock_service/server/spawn.rb
pact-mock_service-0.5.3 lib/pact/mock_service/server/spawn.rb
pact-mock_service-0.5.2 lib/pact/mock_service/server/spawn.rb
pact-mock_service-0.5.1 lib/pact/mock_service/server/spawn.rb
pact-mock_service-0.5.0 lib/pact/mock_service/server/spawn.rb
pact-mock_service-0.4.2 lib/pact/mock_service/server/spawn.rb
pact-mock_service-0.4.1 lib/pact/mock_service/server/spawn.rb
pact-mock_service-0.4.0 lib/pact/mock_service/server/spawn.rb
pact-mock_service-0.3.0 lib/pact/mock_service/server/spawn.rb