Files
ubicloud/bin/production_check
Jeremy Evans 6d568f373b Double bin/production_check timeout
Hopefully will fix issues on arm64 CI.
2025-05-08 08:42:53 +09:00

69 lines
1.6 KiB
Ruby
Executable File

#!/usr/bin/env ruby
# frozen_string_literal: true
Dir.chdir(File.dirname(__dir__))
require "open3"
require "net/http"
require "json"
works = nil
error = +""
queue = Queue.new
Open3.popen3({"RACK_ENV" => "production", "PORT" => "8081", "WEB_CONCURRENCY" => "1"}, "bundle", "exec", "puma", "-C", "puma_config.rb") do |stdin, stdout, stderr, wait_thr|
pid = wait_thr.pid
timer_thread = Thread.new do
queue.pop(timeout: 12)
if works.nil?
error = "Timeout"
Process.kill(:KILL, pid)
end
end
stdout_thread = Thread.new do
while (line = stdout.gets)
case line
when /\A\[\d+\] - Worker 0 \(PID: \d+\) booted in \d+.\d+s, phase: 0/
puts line
response = Net::HTTP.post(URI("http://localhost:8081/login"),
{"login" => "foo@example.com", "password" => "bar"}.to_json,
{"content-type" => "application/json", "host" => "api.localhost"})
works = response.is_a?(Net::HTTPUnauthorized)
queue.push(true)
Process.kill(:TERM, pid)
puts stdout.read
break
when /\A! Unable to load application: /
error << line
works = false
queue.push(true)
Process.kill(:TERM, pid)
break
else
puts line
end
end
end
stderr_thread = Thread.new do
err = stderr.read(1)
if !err.nil?
error << err << stderr.read_nonblock(100000)
unless /"POST \/login HTTP\/1\.1*" 401 \d+ \d\.\d+\n\z/.match?(error)
works = false
queue.push(true)
Process.kill(:TERM, pid)
end
end
end
[stdout_thread, stderr_thread, timer_thread].map(&:join)
end
unless works
warn error
exit(1)
end