2012-01-08 16:55:57 -03:00
|
|
|
require "rbconfig"
|
2011-12-07 13:43:16 -08:00
|
|
|
require 'test/unit'
|
2011-12-07 13:53:36 -08:00
|
|
|
require 'socket'
|
2011-12-07 13:43:16 -08:00
|
|
|
|
2011-12-07 14:48:41 -08:00
|
|
|
require 'puma/cli'
|
|
|
|
require 'puma/control_cli'
|
|
|
|
|
2011-12-07 13:43:16 -08:00
|
|
|
class TestIntegration < Test::Unit::TestCase
|
|
|
|
def setup
|
|
|
|
@state_path = "test/test_puma.state"
|
|
|
|
@bind_path = "test/test_server.sock"
|
|
|
|
@control_path = "test/test_control.sock"
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
File.unlink @state_path rescue nil
|
|
|
|
File.unlink @bind_path rescue nil
|
|
|
|
File.unlink @control_path rescue nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_stop_via_pumactl
|
2012-01-08 16:55:57 -03:00
|
|
|
if defined?(JRUBY_VERSION) || RbConfig::CONFIG["host_os"] =~ /mingw|mswin/
|
2011-12-07 14:58:30 -08:00
|
|
|
assert true
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2011-12-07 14:48:41 -08:00
|
|
|
sin = StringIO.new
|
|
|
|
sout = StringIO.new
|
2011-12-07 13:43:16 -08:00
|
|
|
|
2011-12-07 14:48:41 -08:00
|
|
|
cli = Puma::CLI.new %W!-q -S #{@state_path} -b unix://#{@bind_path} --control unix://#{@control_path} test/hello.ru!, sin, sout
|
2011-12-07 13:43:16 -08:00
|
|
|
|
2011-12-07 14:48:41 -08:00
|
|
|
t = Thread.new do
|
|
|
|
cli.run
|
2011-12-07 13:43:16 -08:00
|
|
|
end
|
|
|
|
|
2011-12-07 13:53:36 -08:00
|
|
|
sleep 1
|
|
|
|
|
|
|
|
s = UNIXSocket.new @bind_path
|
|
|
|
s << "GET / HTTP/1.0\r\n\r\n"
|
|
|
|
assert_equal "Hello World", s.read.split("\r\n").last
|
|
|
|
|
2011-12-07 14:48:41 -08:00
|
|
|
ccli = Puma::ControlCLI.new %W!-S #{@state_path} stop!, sout
|
2011-12-07 13:43:16 -08:00
|
|
|
|
2011-12-07 14:48:41 -08:00
|
|
|
ccli.run
|
2011-12-07 13:43:16 -08:00
|
|
|
|
2011-12-07 14:48:41 -08:00
|
|
|
assert_kind_of Thread, t.join(1), "server didn't stop"
|
2011-12-07 13:43:16 -08:00
|
|
|
end
|
|
|
|
end
|