Skip to content

Commit

Permalink
Merge pull request #108 from gpad/win-error
Browse files Browse the repository at this point in the history
Win error
  • Loading branch information
evanphx committed Jun 22, 2012
2 parents 680be41 + 8d33d33 commit 067f573
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
20 changes: 14 additions & 6 deletions lib/puma/cli.rb
Expand Up @@ -419,14 +419,22 @@ def run
@status = status
end

Signal.trap "SIGUSR2" do
@restart = true
server.begin_restart
begin
Signal.trap "SIGUSR2" do
@restart = true
server.begin_restart
end
rescue Exception
log "*** Sorry signal SIGUSR2 not implemented, restart feature disabled!"
end

Signal.trap "SIGTERM" do
log " - Gracefully stopping, waiting for requests to finish"
server.stop false
begin
Signal.trap "SIGTERM" do
log " - Gracefully stopping, waiting for requests to finish"
server.stop false
end
rescue Exception
log "*** Sorry signal SIGTERM not implemented, gracefully stopping feature disabled!"
end

log "Use Ctrl-C to stop"
Expand Down
31 changes: 31 additions & 0 deletions test/test_cli.rb
Expand Up @@ -28,6 +28,37 @@ def test_pid_file
assert_equal File.read(@tmp_path).strip.to_i, Process.pid
end

def test_control_for_tcp
url = "tcp://127.0.0.1:9877/"
sin = StringIO.new
sout = StringIO.new
cli = Puma::CLI.new ["-b", "tcp://127.0.0.1:9876",
"--control", url,
"--control-token", "",
"test/lobster.ru"], sin, sout
cli.parse_options

thread_exception = nil
t = Thread.new do
begin
cli.run
rescue Exception => e
thread_exception = e
end
end

sleep 1

s = TCPSocket.new "127.0.0.1", 9877
s << "GET /stats HTTP/1.0\r\n\r\n"
body = s.read
assert_equal '{ "backlog": 0, "running": 0 }', body.split("\r\n").last

cli.stop
t.join
assert_equal nil, thread_exception
end

unless defined?(JRUBY_VERSION) || RbConfig::CONFIG["host_os"] =~ /mingw|mswin/
def test_control
url = "unix://#{@tmp_path}"
Expand Down
10 changes: 5 additions & 5 deletions test/test_rack_server.rb
Expand Up @@ -66,7 +66,7 @@ def test_lint

@server.run

hit(['http://localhost:9998/test'])
hit(['http://127.0.0.1:9998/test'])

stop

Expand All @@ -83,7 +83,7 @@ def test_large_post_body

big = "x" * (1024 * 16)

Net::HTTP.post_form URI.parse('http://localhost:9998/test'),
Net::HTTP.post_form URI.parse('http://127.0.0.1:9998/test'),
{ "big" => big }

stop
Expand All @@ -98,7 +98,7 @@ def test_path_info
@server.app = lambda { |env| input = env; @simple.call(env) }
@server.run

hit(['http://localhost:9998/test/a/b/c'])
hit(['http://127.0.0.1:9998/test/a/b/c'])

stop

Expand All @@ -115,7 +115,7 @@ def test_after_reply

@server.run

hit(['http://localhost:9998/test'])
hit(['http://127.0.0.1:9998/test'])

stop

Expand All @@ -131,7 +131,7 @@ def test_common_logger

@server.run

hit(['http://localhost:9998/test'])
hit(['http://127.0.0.1:9998/test'])

stop

Expand Down
2 changes: 1 addition & 1 deletion test/test_ws.rb
Expand Up @@ -37,7 +37,7 @@ def teardown
end

def test_simple_server
hit(['http://localhost:9998/test'])
hit(['http://127.0.0.1:9998/test'])
assert @tester.ran_test, "Handler didn't really run"
end

Expand Down

0 comments on commit 067f573

Please sign in to comment.