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
81
82
|
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)
sleep 1; spawn("tail -f #{test_log}")
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
|