class Gitlab::QA::Component::Gitlab::Availability

Public Class Methods

new(name, relative_path: '', scheme: 'http', protocol_port: 80) click to toggle source
# File lib/gitlab/qa/component/gitlab.rb, line 171
def initialize(name, relative_path: '', scheme: 'http', protocol_port: 80)
  @docker = Docker::Engine.new

  host = @docker.hostname
  port = @docker.port(name, protocol_port).split(':').last

  @uri = URI.join("#{scheme}://#{host}:#{port}", "#{relative_path}/", 'help')
end

Public Instance Methods

check(retries) click to toggle source
# File lib/gitlab/qa/component/gitlab.rb, line 180
def check(retries)
  print "Waiting for GitLab at `#{@uri}` to become available "

  retries.times do
    return true if service_available?

    print '.'
    sleep 1
  end

  false
end

Private Instance Methods

opts() click to toggle source
# File lib/gitlab/qa/component/gitlab.rb, line 207
def opts
  @uri.scheme == 'https' ? { use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE } : {}
end
service_available?() click to toggle source
# File lib/gitlab/qa/component/gitlab.rb, line 195
def service_available?
  response = Net::HTTP.start(@uri.host, @uri.port, opts) do |http|
    http.head2(@uri.request_uri)
  end

  print response.code
  response.code.to_i == 200
rescue Errno::ECONNREFUSED, Errno::ECONNRESET, EOFError => e
  print e.message
  false
end