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

test-boot « _support - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3c8638637596eee1ea38ae12ded3dc3276f7df30 (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
81
82
83
84
#!/usr/bin/env ruby

require 'tempfile'
require 'socket'

ADDR = 'socket'.freeze

def main(gitaly_dir)
  gitaly_dir = File.realpath(gitaly_dir)
  bin_dir = File.join(gitaly_dir, '_build', 'bin')

  version = IO.popen("#{File.join(bin_dir, 'gitaly')} -version").read.delete_prefix('Gitaly, version ').strip
  version_from_file = IO.read(File.join(gitaly_dir, 'VERSION')).strip

  # Use start_with? instead of == because the version output could use git describe, if it is a source install
  # eg: Gitaly, version 1.75.0-14-gd1ecb43f
  abort "\nversion check failed: VERSION file contained '#{version_from_file}' but 'gitaly -version' reported '#{version}'."\
  " If you are working from a fork, please fetch the latest tags." unless version.start_with?(version_from_file)

  Dir.mktmpdir do |dir|
    Dir.chdir(dir)
    File.write(File.join("#{gitaly_dir}/ruby/git-hooks", '.gitlab_shell_secret'), 'test_gitlab_shell_token')

    File.write('config.toml', <<~CONFIG
      socket_path = "#{ADDR}"
      bin_dir = "#{bin_dir}"

      [[storage]]
      name = "default"
      path = "#{dir}"

      [gitaly-ruby]
      dir = "#{gitaly_dir}/ruby"

      [gitlab-shell]
      dir = "#{gitaly_dir}/ruby/git-hooks"

      [gitlab]
      url = 'http://gitlab_url'

      CONFIG
              )

    pid = nil

    begin
      start = Time.now
      pid = spawn(File.join(bin_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)