<commit_before>require 'timeout'
require 'net/http'

module Pact
  module MockService
    module Server
      class WaitForServerUp

        def self.call(port, options = {ssl: false})
          tries = 0
          while !responsive?(port, options) && tries < 100
            tries += 1
            sleep 1
          end

        end

        def self.responsive? port, options
          res = Net::HTTP.start("localhost", port) do |http|
            request = Net::HTTP::Get.new "http://localhost:#{port}/__identify__"
            request['X-Pact-Mock-Service'] = 'true'
            response = http.request request
          end
          true
        rescue SystemCallError => e
          return false
        rescue EOFError
          return false
        end
      end

    end
  end
end
<commit_msg>Timeout if server does not become responsive in the given time<commit_after>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}/__identify__"
            request['X-Pact-Mock-Service'] = 'true'
            response = http.request request
          end
          true
        rescue SystemCallError => e
          return false
        rescue EOFError
          return false
        end
      end

    end
  end
end

{'fraction_non_alphanumeric': 0.08491620111731843, 'fraction_numerical': 0.0067039106145251395, 'mean_word_length': 1.7427258805513017, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '409282', 'n_tokens_mistral': 486, 'n_tokens_neox': 469, 'n_words': 153}