Welcome to mirror list, hosted at ThFree Co, Russian Federation.

integration_helper.rb « spec « ruby - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f76e640ff9ed6b2595576ae80a6ad6f52f029819 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
require 'socket'

require 'gitaly'
require 'spec_helper'

SOCKET_PATH = 'gitaly.socket'.freeze
TMP_DIR = File.expand_path('../../tmp', __FILE__)

module IntegrationClient
  def gitaly_stub(service)
    klass = Gitaly.const_get(service).const_get(:Stub)
    klass.new("unix:tmp/#{SOCKET_PATH}", :this_channel_is_insecure)
  end

  def gitaly_repo(storage, relative_path)
    Gitaly::Repository.new(storage_name: storage, relative_path: relative_path)
  end
end

def start_gitaly
  build_dir = File.expand_path('../../../_build', __FILE__)
  gitlab_shell_dir = File.join(TMP_DIR, 'gitlab-shell')

  FileUtils.mkdir_p([TMP_DIR, File.join(gitlab_shell_dir, 'hooks')])

  config_toml = <<~CONFIG
    socket_path = "#{SOCKET_PATH}"
    bin_dir = "#{build_dir}/bin"
    
    [gitlab-shell]
    dir = "#{gitlab_shell_dir}"
    
    [gitaly-ruby]
    dir = "#{build_dir}/assembly/ruby"
    
    [[storage]]
    name = "#{DEFAULT_STORAGE_NAME}"
    path = "#{DEFAULT_STORAGE_DIR}"
  CONFIG
  config_path = File.join(TMP_DIR, 'gitaly-rspec-config.toml')
  File.write(config_path, config_toml)

  test_log = File.join(TMP_DIR, 'gitaly-rspec-test.log')
  options = { out: test_log, err: test_log, chdir: TMP_DIR }
  gemfile = File.expand_path('../../Gemfile', __FILE__)
  env = {
    'GEM_PATH' => Gem.path.join(':'),
    'BUNDLE_APP_CONFIG' => File.join(File.dirname(gemfile), '.bundle/config'),
    'BUNDLE_GEMFILE' => gemfile,
    'RUBYOPT' => nil
  }

  gitaly_pid = spawn(env, File.join(build_dir, 'bin/gitaly'), config_path, options)

  at_exit { Process.kill('KILL', gitaly_pid) }

  wait_ready!(File.join('tmp', SOCKET_PATH))
end

def wait_ready!(socket)
  last_exception = StandardError.new('wait_ready! has not made any connection attempts')

  print('Booting gitaly for integration tests')
  100.times do |i|
    sleep 0.1
    printf('.')
    begin
      UNIXSocket.new(socket).close
      puts ' ok'
      return
    rescue => ex
      last_exception = ex
    end
  end

  puts
  raise last_exception
end

start_gitaly