diff options
author | jramsay <jcai@gitlab.com> | 2019-10-22 04:21:54 +0300 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2019-11-20 04:36:55 +0300 |
commit | 7d4a9c5be6a37cfd000df00bf71ed70103eb7845 (patch) | |
tree | ad1703b9cb6edb6332b33fb2cdcbe56af8a02c06 /_support/test-boot | |
parent | 78f16381648b2d1857d01c39eeef25035599cffb (diff) |
Validate that hook files are reachable and executable
Diffstat (limited to '_support/test-boot')
-rwxr-xr-x | _support/test-boot | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/_support/test-boot b/_support/test-boot new file mode 100755 index 000000000..1d7b19f28 --- /dev/null +++ b/_support/test-boot @@ -0,0 +1,70 @@ +#!/usr/bin/env ruby + +require 'tempfile' +require 'socket' + +ADDR = 'socket'.freeze + +def main(gitaly_dir) + gitaly_dir = File.realpath(gitaly_dir) + + Dir.mktmpdir do |dir| + Dir.chdir(dir) + + File.write('config.toml', <<~CONFIG + socket_path = "#{ADDR}" + bin_dir = "#{gitaly_dir}" + + [[storage]] + name = "default" + path = "#{dir}" + + [gitaly-ruby] + dir = "#{gitaly_dir}/ruby" + + [gitlab-shell] + dir = "#{gitaly_dir}/ruby/gitlab-shell" + CONFIG + ) + + pid = nil + + begin + start = Time.now + pid = spawn(File.join(gitaly_dir, 'gitaly'), 'config.toml') + wait_connect + puts + puts "\n\nconnection established after #{Time.now - start} seconds\n\n" + ensure + if pid + Process.kill("KILL", pid) + Process.wait(pid) + end + end + end +end + +def wait_connect + repeats = 100 + sleep_time = 0.1 + + repeats.times do + begin + Socket.unix(ADDR) + return + rescue # rubocop:disable Lint/RescueWithoutErrorClass + print '.' + sleep(sleep_time) + end + end + + puts "failed to connect to gitaly after #{repeats * sleep_time}s" + + abort +end + +unless ARGV.count == 1 + abort "Usage: #{$PROGRAM_NAME} GITALY_DIR" +end + +main(ARGV.first) |