summaryrefslogtreecommitdiff
path: root/spec/support/server.rb
blob: d96239a29300a81765e7b98cc4e531e42b05929a (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
# frozen_string_literal: true
require 'socket'

RSpec.configure do |config|
  config.add_setting :http
  config.http = Net::Hippie::Client.new

  config.add_setting :bind_addr
  config.bind_addr = ENV.fetch("BIND_ADDR", "127.0.0.1:7878")

  config.add_setting :pid

  config.before :suite do
    bind_addr = RSpec.configuration.bind_addr
    RSpec.configuration.pid = Process.spawn({
      "BIND_ADDR" => bind_addr,
    }, "mise exec -- cargo run")

    ip, port = bind_addr.split(":")
    300.times do |n|
      begin
        Socket.tcp(ip, port.to_i) { true }
        break
      rescue Errno::ECONNREFUSED => error
        sleep 1
      end
    end
  end

  config.after :suite do
    Process.kill('SIGTERM', RSpec.configuration.pid)
    system("killall sts")
  end
end

at_exit do
  system("killall sts")
end