1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00
puma--puma/test/test_pumactl.rb
John Andrews 6d0efee913 Add support for --control-url (#1487)
- deprecate `--control`
- add new option `--control-url`
- https://github.com/puma/puma/pull/1416 introduced a bug in pumactl the puma
  cli does not respond to `control-cli` option. On puma it is called `control`
- this commit
  a8f54f74cd
  was correct, but it looked like a typo since the names of the options are not
  consistent across versions
- the best option for fixing this seems to be to support both options
- we don't want to stop supporting `control` in the cli for
  backwards-compatibility so it is deprecated
2018-05-09 12:38:12 -06:00

68 lines
1.4 KiB
Ruby

require_relative "helper"
require 'puma/control_cli'
class TestPumaControlCli < Minitest::Test
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
def test_config_file
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")
end
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
end