Sha256: c14583575c3c697dbe3b4ab0c9cdc9598d9f604d8a1ba78edb6c12bea71300f6

Contents?: true

Size: 1.13 KB

Versions: 25

Compression:

Stored size: 1.13 KB

Contents

require 'timeout'
require 'net/http'
require 'openssl'

module Pact
  module MockService
    module Server
      class WaitForServerUp

        def self.call(host, port, options = {ssl: false})
          tries = 0
          responsive = false
          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? host, port, options
          http = Net::HTTP.new(host, port)
          if options[:ssl]
            http.use_ssl = true
            http.verify_mode = OpenSSL::SSL::VERIFY_NONE
            scheme = 'https'
          else
            scheme = 'http'
          end
          http.start {
            request = Net::HTTP::Get.new "#{scheme}://#{host}:#{port}/"
            request['X-Pact-Mock-Service'] = true
            response = http.request request
            response.code == '200'
          }
        rescue SystemCallError => e
          return false
        rescue EOFError
          return false
        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/wait_for_server_up.rb
pact-mock_service-3.12.2 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-3.12.1 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-3.12.0 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-3.11.2 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-3.11.1 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-3.11.0 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-3.10.0 lib/pact/mock_service/server/wait_for_server_up.rb
hs-pact-mock_service-3.9.2 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-3.9.1 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-3.9.0 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-3.8.0 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-3.7.0 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-3.6.2 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-3.6.1 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-3.6.0 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-3.5.0 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-3.4.0 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-3.3.1 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-3.3.0 lib/pact/mock_service/server/wait_for_server_up.rb