Skip to content

Commit

Permalink
Add two simple UNIXSocket tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MSP-Greg committed Apr 21, 2021
1 parent a588088 commit 23173a1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
24 changes: 24 additions & 0 deletions test/test_pumactl.rb
Expand Up @@ -175,6 +175,30 @@ def test_control_ssl
assert_kind_of Thread, t.join, "server didn't stop"
end

def test_control_aunix
skip_unless :aunix

url = "unix://@test_control_aunix.unix"

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
control_cli.run
end

wait_booted

assert_command_cli_output opts + ["status"], "Puma is started"
assert_command_cli_output opts + ["stop"], "Command stop sent success"

assert_kind_of Thread, t.join, "server didn't stop"
end

private

def assert_command_cli_output(options, expected_out)
Expand Down
30 changes: 21 additions & 9 deletions test/test_unix_socket.rb
Expand Up @@ -8,21 +8,21 @@ class TestPumaUnixSocket < Minitest::Test

App = lambda { |env| [200, {}, ["Works"]] }

def setup
return unless UNIX_SKT_EXIST
@tmp_socket_path = tmp_path('.sock')
def teardown
return if skipped?
@server.stop(true)
end

def server_unix(type)
@tmp_socket_path = type == :unix ? tmp_path('.sock') : "@TestPumaUnixSocket"
@server = Puma::Server.new App
@server.add_unix_listener @tmp_socket_path
@server.run
end

def teardown
return unless UNIX_SKT_EXIST
@server.stop(true)
end

def test_server
def test_server_unix
skip_unless :unix
server_unix :unix
sock = UNIXSocket.new @tmp_socket_path

sock << "GET / HTTP/1.0\r\nHost: blah.com\r\n\r\n"
Expand All @@ -31,4 +31,16 @@ def test_server

assert_equal expected, sock.read(expected.size)
end

def test_server_aunix
skip_unless :aunix
server_unix :aunix
sock = UNIXSocket.new @tmp_socket_path.sub(/\A@/, "\0")

sock << "GET / HTTP/1.0\r\nHost: blah.com\r\n\r\n"

expected = "HTTP/1.0 200 OK\r\nContent-Length: 5\r\n\r\nWorks"

assert_equal expected, sock.read(expected.size)
end
end

0 comments on commit 23173a1

Please sign in to comment.