Sha256: c7aa292574f737bfc5545a7f6bf8a368c50c468a054c6b15016d64714a1782f2

Contents?: true

Size: 911 Bytes

Versions: 21

Compression:

Stored size: 911 Bytes

Contents

require 'timeout'
require 'net/http'

module Pact
  module MockService
    module Server
      class WaitForServerUp

        def self.call(port, options = {ssl: false})
          tries = 0
          responsive = false
          while !(responsive = responsive?(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
          res = Net::HTTP.start("localhost", port) do |http|
            request = Net::HTTP::Get.new "http://localhost:#{port}/"
            request['X-Pact-Mock-Service'] = 'true'
            response = http.request request
          end
          res.code == '200'
        rescue SystemCallError => e
          return false
        rescue EOFError
          return false
        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/wait_for_server_up.rb
pact-mock_service-0.10.0 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-0.9.0 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-0.8.2 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-0.8.1 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-0.8.0 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-0.7.2 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-0.7.1 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-0.7.0 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-0.6.0 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-0.5.5 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-0.5.4 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-0.5.3 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-0.5.2 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-0.5.1 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-0.5.0 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-0.4.2 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-0.4.1 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-0.4.0 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-0.3.0 lib/pact/mock_service/server/wait_for_server_up.rb