mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
d39fe92a2d
* Fix crash when no_token is set * Use a more meaningful name instead of an empty string * Adds a test to ensure `{ no_token: true }` works * Adds an explanation for the usage of a String Just to justify the use of a String instead of a Symbol. * Removes thread that would start the server This removes the part of the test that would start the server. The reason why the thread was being created originally in the PR was to ensure that the server was booting even with `{ no_token: true }`. I believe we don't need to test the full server boot but just ensure that we won't pass a Symbol to OptionParser. In particular the test ensures that the token will be set to `'none'` when `no_token: true`. There're already other tests testing that the server boots.
74 lines
1.6 KiB
Ruby
74 lines
1.6 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
|
|
server = TCPServer.new("127.0.0.1", 0)
|
|
server.addr[1]
|
|
ensure
|
|
server.close
|
|
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_no_token
|
|
opts = [
|
|
"--config-file", "test/config/control_no_token.rb",
|
|
"start"
|
|
]
|
|
|
|
control_cli = Puma::ControlCLI.new opts, @ready, @ready
|
|
assert_equal 'none', control_cli.instance_variable_get("@control_auth_token")
|
|
end
|
|
|
|
def test_control_url
|
|
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
|