Skip to content

Commit

Permalink
tests - cleanup rackup folder, add sleep.ru, add helpers/app.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
MSP-Greg committed Aug 11, 2019
1 parent cbf1bd1 commit d022ba4
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 53 deletions.
1 change: 1 addition & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
require "minitest/autorun"
require "minitest/pride"
require "minitest/proveit"
require_relative "helpers/apps"

$LOAD_PATH << File.expand_path("../../lib", __FILE__)
Thread.abort_on_exception = true
Expand Down
12 changes: 12 additions & 0 deletions test/helpers/apps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module TestApps

# call with "GET /sleep<d> HTTP/1.1\r\n\r\n", where is the number of
# seconds to sleep
# same as rackup/sleep.ru
SLEEP = -> (env) do
dly = (env['REQUEST_PATH'][/\/sleep(\d+)/,1] || '0').to_i
sleep dly
[200, {"Content-Type" => "text/plain"}, ["Slept #{dly}"]]
end

end
4 changes: 0 additions & 4 deletions test/rackup/10seconds.ru

This file was deleted.

4 changes: 0 additions & 4 deletions test/rackup/1second.ru

This file was deleted.

3 changes: 0 additions & 3 deletions test/rackup/hello-delay.ru

This file was deleted.

3 changes: 0 additions & 3 deletions test/rackup/hello-map.ru

This file was deleted.

4 changes: 0 additions & 4 deletions test/rackup/hello-post.ru

This file was deleted.

1 change: 0 additions & 1 deletion test/rackup/hello-stuck-ci.ru

This file was deleted.

1 change: 0 additions & 1 deletion test/rackup/hello-stuck.ru

This file was deleted.

5 changes: 0 additions & 5 deletions test/rackup/hello-tcp.ru

This file was deleted.

6 changes: 0 additions & 6 deletions test/rackup/hijack.ru

This file was deleted.

5 changes: 0 additions & 5 deletions test/rackup/hijack2.ru

This file was deleted.

9 changes: 9 additions & 0 deletions test/rackup/sleep.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# call with "GET /sleep<d> HTTP/1.1\r\n\r\n", where <d> is the number of
# seconds to sleep
# same as TestApps.sleep

run lambda { |env|
dly = (env['REQUEST_PATH'][/\/sleep(\d+)/,1] || '0').to_i
sleep dly
[200, {"Content-Type" => "text/plain"}, ["Slept #{dly}"]]
}
4 changes: 0 additions & 4 deletions test/rackup/slow.ru

This file was deleted.

25 changes: 12 additions & 13 deletions test/test_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ def restart_server(server, connection)
wait_for_server_to_boot(server)
end

def connect
def connect(path = nil)
s = TCPSocket.new "localhost", @tcp_port
s << "GET / HTTP/1.1\r\n\r\n"
s << "GET /#{path} HTTP/1.1\r\n\r\n"
true until s.gets == "\r\n"
s
end
Expand Down Expand Up @@ -158,17 +158,16 @@ def test_stop_via_pumactl
def test_phased_restart_via_pumactl
skip NO_FORK_MSG unless HAS_FORK

# hello-stuck-ci uses sleep 10, hello-stuck uses sleep 60
rackup = "test/rackup/hello-stuck#{ ENV['CI'] ? '-ci' : '' }.ru"
delay = ENV['CI'] ? 20 : 60

conf = Puma::Configuration.new do |c|
c.quiet
c.state_path @state_path
c.bind "unix://#{@bind_path}"
c.activate_control_app "unix://#{@control_path}", :auth_token => @token
c.workers 2
c.worker_shutdown_timeout 1
c.rackup rackup
c.worker_shutdown_timeout 2
c.rackup "test/rackup/sleep.ru"
end

l = Puma::Launcher.new conf, :events => @events
Expand All @@ -181,7 +180,7 @@ def test_phased_restart_via_pumactl
wait_booted

s = UNIXSocket.new @bind_path
s << "GET / HTTP/1.0\r\n\r\n"
s << "GET /sleep#{delay} HTTP/1.0\r\n\r\n"

sout = StringIO.new
# Phased restart
Expand Down Expand Up @@ -241,15 +240,15 @@ def test_restart_closes_keepalive_sockets_workers

def test_sigterm_closes_listeners_on_forked_servers
skip NO_FORK_MSG unless HAS_FORK
pid = start_forked_server("-w 2 -q test/rackup/1second.ru")
pid = start_forked_server("-w 2 -q test/rackup/sleep.ru")
threads = []
initial_reply = nil
next_replies = []
condition_variable = ConditionVariable.new
mutex = Mutex.new

threads << Thread.new do
s = connect
s = connect "sleep1"
mutex.synchronize { condition_variable.broadcast }
initial_reply = read_body(s)
end
Expand Down Expand Up @@ -284,7 +283,7 @@ def test_sigterm_closes_listeners_on_forked_servers

threads.map(&:join)

assert_equal "Hello World", initial_reply
assert_equal "Slept 1", initial_reply

assert_includes next_replies, :connection_refused

Expand Down Expand Up @@ -351,9 +350,9 @@ def test_term_signal_suppress_in_clustered_mode
def test_not_accepts_new_connections_after_term_signal
skip_on :jruby, :windows

server('test/rackup/10seconds.ru')
server('test/rackup/sleep.ru')

_stdin, curl_stdout, _stderr, curl_wait_thread = Open3.popen3("curl 127.0.0.1:#{@tcp_port}")
_stdin, curl_stdout, _stderr, curl_wait_thread = Open3.popen3("curl http://127.0.0.1:#{@tcp_port}/sleep10")
sleep 1 # ensure curl send a request

Process.kill(:TERM, @server.pid)
Expand All @@ -368,7 +367,7 @@ def test_not_accepts_new_connections_after_term_signal
curl_wait_thread.join
rejected_curl_wait_thread.join

assert_match(/Hello World/, curl_stdout.read)
assert_match(/Slept 10/, curl_stdout.read)
assert_match(/Connection refused/, rejected_curl_stderr.read)

Process.wait(@server.pid)
Expand Down

0 comments on commit d022ba4

Please sign in to comment.