1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

simplify test shellout and make sure no other version of puma is available so we know our tests work (#1311)

This commit is contained in:
Michael Grosser 2017-06-02 13:24:01 -07:00 committed by Nate Berkopec
parent fec20f0f05
commit febef44844
4 changed files with 33 additions and 50 deletions

View file

@ -143,6 +143,16 @@ else
task :test => [:compile]
end
task :test => [:ensure_no_puma_gem]
task :ensure_no_puma_gem do
Bundler.with_clean_env do
out = `gem list puma`.strip
if !$?.success? || out != ""
abort "No other puma version should be install to avoid false positives or lading it by accident but found #{out}"
end
end
end
namespace :test do
desc "Run the integration tests"
task :integration do

View file

@ -340,8 +340,6 @@ module Puma
@restart_dir ||= Dir.pwd
require 'rubygems'
# if $0 is a file in the current directory, then restart
# it the same, otherwise add -S on there because it was
# picked up in PATH.
@ -352,9 +350,10 @@ module Puma
arg0 = [Gem.ruby, "-S", $0]
end
# Detect and reinject -Ilib from the command line
# Detect and reinject -Ilib from the command line, used for testing without bundler
# cruby has an expanded path, jruby has just "lib"
lib = File.expand_path "lib"
arg0[1,0] = ["-I", lib] if $:[0] == lib
arg0[1,0] = ["-I", lib] if [lib, "lib"].include?($LOAD_PATH[0])
if defined? Puma::WILD_ARGS
@restart_argv = arg0 + Puma::WILD_ARGS + @original_argv

View file

@ -36,10 +36,10 @@ end
module TimeoutEveryTestCase
def run(*)
if !!ENV['CI']
::Timeout.timeout(60) { super }
if ENV['CI']
::Timeout.timeout(Puma.jruby? ? 120 : 60) { super }
else
super
super # we want to be able to use debugger
end
end
end

View file

@ -14,7 +14,6 @@ class TestIntegration < Minitest::Test
@tcp_port = 9998
@server = nil
@script = nil
@wait, @ready = IO.pipe
@ -39,28 +38,25 @@ class TestIntegration < Minitest::Test
@server.close
end
if @script
@script.close!
end
end
def server(opts)
core = "#{Gem.ruby} -rubygems -Ilib bin/puma"
cmd = "#{core} --restart-cmd '#{core}' -b tcp://127.0.0.1:#{@tcp_port} #{opts}"
tf = Tempfile.new "puma-test"
tf.puts "exec #{cmd}"
tf.close
@script = tf
@server = IO.popen("sh #{tf.path}", "r")
def server(argv)
cmd = "#{Gem.ruby} -Ilib bin/puma -b tcp://127.0.0.1:#{@tcp_port} #{argv}"
@server = IO.popen(cmd, "r")
wait_for_server_to_boot
@server
end
def restart_server_and_listen(argv)
server(argv)
s = connect
initial_reply = s.read
restart_server(s)
[initial_reply, connect.read]
end
def signal(which)
Process.kill which, @server.pid
end
@ -135,7 +131,7 @@ class TestIntegration < Minitest::Test
end
def test_phased_restart_via_pumactl
skip("Too finicky, fails 50% of the time on CI.")
skip("Too finicky, fails 50% of the time on CI") if ENV["CI"]
if Puma.jruby? || Puma.windows?
assert true
@ -209,15 +205,8 @@ class TestIntegration < Minitest::Test
end
def test_restart_closes_keepalive_sockets
server("-q test/rackup/hello.ru")
s = connect
s.read
restart_server(s)
s = TCPSocket.new "127.0.0.1", @tcp_port
s << "GET / HTTP/1.0\r\n\r\n"
assert_equal "Hello World", s.read.split("\r\n").last
_, new_reply = restart_server_and_listen("-q test/rackup/hello.ru")
assert_equal "Hello World", new_reply
end
def test_restart_closes_keepalive_sockets_workers
@ -226,15 +215,8 @@ class TestIntegration < Minitest::Test
return
end
server("-q -w 2 test/rackup/hello.ru")
s = connect
s.read
restart_server s
s = TCPSocket.new "localhost", @tcp_port
s << "GET / HTTP/1.0\r\n\r\n"
assert_equal "Hello World", s.read.split("\r\n").last
_, new_reply = restart_server_and_listen("-q -w 2 test/rackup/hello.ru")
assert_equal "Hello World", new_reply
end
# It does not share environments between multiple generations, which would break Dotenv
@ -246,15 +228,7 @@ class TestIntegration < Minitest::Test
return
end
server("-q test/rackup/hello-env.ru")
s = connect
initial_reply = s.read
restart_server(s)
s = TCPSocket.new "localhost", @tcp_port
s << "GET / HTTP/1.0\r\n\r\n"
new_reply = s.read.split("\r\n").last
initial_reply, new_reply = restart_server_and_listen("-q test/rackup/hello-env.ru")
assert_includes initial_reply, "Hello RAND"
assert_includes new_reply, "Hello RAND"