Sha256: d1f61fbec331464b5069b79b6250f02fd642c3ebcfa8105c2358c8722f064e5f

Contents?: true

Size: 1.12 KB

Versions: 35

Compression:

Stored size: 1.12 KB

Contents

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

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
          http = Net::HTTP.new('localhost', 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}://localhost:#{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

35 entries across 35 versions & 1 rubygems

Version Path
pact-mock_service-3.0.0 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-2.12.0 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-2.11.0 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-2.10.1 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-2.10.0 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-2.9.8 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-2.9.3 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-2.9.2 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-2.9.1 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-2.9.0 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-2.8.1 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-2.8.0 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-2.7.1 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-2.7.0 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-2.6.4 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-2.6.3 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-2.6.2 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-2.6.0 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-2.5.4 lib/pact/mock_service/server/wait_for_server_up.rb
pact-mock_service-2.5.3 lib/pact/mock_service/server/wait_for_server_up.rb