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

minor test cleanups

git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@710 19e92222-5c0b-0410-8929-a290d50e31e9
This commit is contained in:
evanweaver 2007-10-21 02:54:53 +00:00
parent 0320048974
commit c60ff81f1e
3 changed files with 79 additions and 68 deletions

View file

@ -266,9 +266,9 @@ module Mongrel
update_request_progress(remain, total)
end
rescue Object
STDERR.puts "#{Time.now}: Error reading HTTP body: #$!"
STDERR.puts $!.backtrace.join("\n")
rescue Object => e
STDERR.puts "#{Time.now}: Error reading HTTP body: #{e.inspect}"
STDERR.puts e.backtrace.join("\n")
# any errors means we should delete the file, including if the file is dumped
@socket.close rescue nil
@body.delete if @body.class == Tempfile
@ -657,16 +657,23 @@ module Mongrel
end
rescue EOFError,Errno::ECONNRESET,Errno::EPIPE,Errno::EINVAL,Errno::EBADF
client.close rescue nil
rescue HttpParserError
STDERR.puts "#{Time.now}: HTTP parse error, malformed request (#{params[Const::HTTP_X_FORWARDED_FOR] || client.peeraddr.last}): #$!"
rescue HttpParserError => e
STDERR.puts "#{Time.now}: HTTP parse error, malformed request (#{params[Const::HTTP_X_FORWARDED_FOR] || client.peeraddr.last}): #{e.inspect}"
STDERR.puts "#{Time.now}: REQUEST DATA: #{data.inspect}\n---\nPARAMS: #{params.inspect}\n---\n"
rescue Errno::EMFILE
reap_dead_workers('too many files')
rescue Object
STDERR.puts "#{Time.now}: Error: #$!"
STDERR.puts $!.backtrace.join("\n")
rescue Object => e
STDERR.puts "#{Time.now}: Read error: #{e.inspect}"
STDERR.puts e.backtrace.join("\n")
ensure
client.close rescue nil
begin
client.close
rescue IOError
# Already closed
rescue Object => e
STDERR.puts "#{Time.now}: Client error: #{e.inspect}"
STDERR.puts e.backtrace.join("\n")
end
request.body.delete if request and request.body.class == Tempfile
end
end
@ -763,9 +770,9 @@ module Mongrel
rescue Errno::ECONNABORTED
# client closed the socket even before accept
client.close rescue nil
rescue Object => exc
STDERR.puts "** Unhandled exception #{exc.inspect}."
STDERR.puts $!.backtrace.join("\n")
rescue Object => e
STDERR.puts "#{Time.now}: Unhandled listen loop exception #{e.inspect}."
STDERR.puts e.backtrace.join("\n")
end
end
graceful_shutdown

View file

@ -4,63 +4,67 @@
# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html
# for more information.
HERE = File.dirname(__FILE__)
%w(lib ext bin test).each do |dir|
$LOAD_PATH.unshift "#{HERE}/../#{dir}"
end
unless defined? $require_once
require 'rubygems'
require 'test/unit'
require 'net/http'
require 'timeout'
require 'cgi/session'
require 'fileutils'
require 'benchmark'
require 'digest/sha1'
require 'uri'
require 'stringio'
$require_once = true
require 'mongrel'
require 'mongrel/stats'
if ENV['DEBUG']
require 'ruby-debug'
Debugger.start
end
def redirect_test_io
orig_err = STDERR.dup
orig_out = STDOUT.dup
STDERR.reopen("test_stderr.log")
STDOUT.reopen("test_stdout.log")
begin
yield
ensure
STDERR.reopen(orig_err)
STDOUT.reopen(orig_out)
HERE = File.dirname(__FILE__)
%w(lib ext bin test).each do |dir|
$LOAD_PATH.unshift "#{HERE}/../#{dir}"
end
end
# Either takes a string to do a get request against, or a tuple of [URI, HTTP] where
# HTTP is some kind of Net::HTTP request object (POST, HEAD, etc.)
def hit(uris)
results = []
uris.each do |u|
res = nil
if u.kind_of? String
res = Net::HTTP.get(URI.parse(u))
else
url = URI.parse(u[0])
res = Net::HTTP.new(url.host, url.port).start {|h| h.request(u[1]) }
require 'rubygems'
require 'test/unit'
require 'net/http'
require 'timeout'
require 'cgi/session'
require 'fileutils'
require 'benchmark'
require 'digest/sha1'
require 'uri'
require 'stringio'
require 'mongrel'
require 'mongrel/stats'
if ENV['DEBUG']
require 'ruby-debug'
Debugger.start
end
def redirect_test_io
orig_err = STDERR.dup
orig_out = STDOUT.dup
STDERR.reopen("test_stderr.log")
STDOUT.reopen("test_stdout.log")
begin
yield
ensure
STDERR.reopen(orig_err)
STDOUT.reopen(orig_out)
end
assert res != nil, "Didn't get a response: #{u}"
results << res
end
return results
# Either takes a string to do a get request against, or a tuple of [URI, HTTP] where
# HTTP is some kind of Net::HTTP request object (POST, HEAD, etc.)
def hit(uris)
results = []
uris.each do |u|
res = nil
if u.kind_of? String
res = Net::HTTP.get(URI.parse(u))
else
url = URI.parse(u[0])
res = Net::HTTP.new(url.host, url.port).start {|h| h.request(u[1]) }
end
assert res != nil, "Didn't get a response: #{u}"
results << res
end
return results
end
end

View file

@ -18,8 +18,8 @@ def do_test(st, chunk)
break
end
end
rescue Object
STDERR.puts "ERROR: #$!"
rescue Object => e
STDERR.puts "ERROR: #{e}"
ensure
s.close
end