2017-05-12 12:16:55 -07:00
|
|
|
require_relative "helper"
|
2017-03-10 10:02:34 -06:00
|
|
|
|
|
|
|
require 'puma/control_cli'
|
|
|
|
|
|
|
|
class TestPumaControlCli < Minitest::Test
|
2018-05-09 14:38:12 -04:00
|
|
|
def setup
|
|
|
|
# use a pipe to get info across thread boundary
|
|
|
|
@wait, @ready = IO.pipe
|
|
|
|
end
|
|
|
|
|
|
|
|
def wait_booted
|
|
|
|
line = @wait.gets until line =~ /Listening on/
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
@wait.close
|
|
|
|
@ready.close
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_open_port
|
|
|
|
begin
|
|
|
|
server = TCPServer.new("127.0.0.1", 0)
|
|
|
|
server.addr[1]
|
|
|
|
ensure
|
|
|
|
server.close
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-10 10:02:34 -06:00
|
|
|
def test_config_file
|
2017-03-10 10:30:27 -06:00
|
|
|
control_cli = Puma::ControlCLI.new ["--config-file", "test/config/state_file_testing_config.rb", "halt"]
|
|
|
|
assert_equal "t3-pid", control_cli.instance_variable_get("@pidfile")
|
2017-03-10 10:02:34 -06:00
|
|
|
end
|
2018-05-09 14:38:12 -04:00
|
|
|
|
|
|
|
def test_control_url
|
|
|
|
skip if Puma.jruby? || Puma.windows?
|
|
|
|
|
|
|
|
host = "127.0.0.1"
|
|
|
|
port = find_open_port
|
|
|
|
url = "tcp://#{host}:#{port}/"
|
|
|
|
|
|
|
|
opts = [
|
|
|
|
"--control-url", url,
|
|
|
|
"--control-token", "ctrl",
|
|
|
|
"--config-file", "test/config/app.rb",
|
|
|
|
]
|
|
|
|
|
|
|
|
control_cli = Puma::ControlCLI.new (opts + ["start"]), @ready, @ready
|
|
|
|
t = Thread.new do
|
|
|
|
Thread.current.abort_on_exception = true
|
|
|
|
control_cli.run
|
|
|
|
end
|
|
|
|
|
|
|
|
wait_booted
|
|
|
|
|
|
|
|
s = TCPSocket.new host, 9292
|
|
|
|
s << "GET / HTTP/1.0\r\n\r\n"
|
|
|
|
body = s.read
|
|
|
|
assert_match "200 OK", body
|
|
|
|
assert_match "embedded app", body
|
|
|
|
|
|
|
|
shutdown_cmd = Puma::ControlCLI.new(opts + ["halt"])
|
|
|
|
shutdown_cmd.run
|
|
|
|
|
|
|
|
# TODO: assert something about the stop command
|
|
|
|
|
|
|
|
t.join
|
|
|
|
end
|
2017-03-10 10:02:34 -06:00
|
|
|
end
|