Skip to content

Commit

Permalink
minor test cleanups
Browse files Browse the repository at this point in the history
git-svn-id: svn://rubyforge.org/var/svn/mongrel/trunk@710 19e92222-5c0b-0410-8929-a290d50e31e9
  • Loading branch information
evanweaver committed Oct 21, 2007
1 parent 4368502 commit f0f0e74
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 68 deletions.
31 changes: 19 additions & 12 deletions lib/mongrel.rb
Expand Up @@ -266,9 +266,9 @@ def read_body(remain, total)


update_request_progress(remain, total) update_request_progress(remain, total)
end end
rescue Object rescue Object => e
STDERR.puts "#{Time.now}: Error reading HTTP body: #$!" STDERR.puts "#{Time.now}: Error reading HTTP body: #{e.inspect}"
STDERR.puts $!.backtrace.join("\n") STDERR.puts e.backtrace.join("\n")
# any errors means we should delete the file, including if the file is dumped # any errors means we should delete the file, including if the file is dumped
@socket.close rescue nil @socket.close rescue nil
@body.delete if @body.class == Tempfile @body.delete if @body.class == Tempfile
Expand Down Expand Up @@ -657,16 +657,23 @@ def process_client(client)
end end
rescue EOFError,Errno::ECONNRESET,Errno::EPIPE,Errno::EINVAL,Errno::EBADF rescue EOFError,Errno::ECONNRESET,Errno::EPIPE,Errno::EINVAL,Errno::EBADF
client.close rescue nil client.close rescue nil
rescue HttpParserError rescue HttpParserError => e
STDERR.puts "#{Time.now}: HTTP parse error, malformed request (#{params[Const::HTTP_X_FORWARDED_FOR] || client.peeraddr.last}): #$!" 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" STDERR.puts "#{Time.now}: REQUEST DATA: #{data.inspect}\n---\nPARAMS: #{params.inspect}\n---\n"
rescue Errno::EMFILE rescue Errno::EMFILE
reap_dead_workers('too many files') reap_dead_workers('too many files')
rescue Object rescue Object => e
STDERR.puts "#{Time.now}: Error: #$!" STDERR.puts "#{Time.now}: Read error: #{e.inspect}"
STDERR.puts $!.backtrace.join("\n") STDERR.puts e.backtrace.join("\n")
ensure 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 request.body.delete if request and request.body.class == Tempfile
end end
end end
Expand Down Expand Up @@ -763,9 +770,9 @@ def run
rescue Errno::ECONNABORTED rescue Errno::ECONNABORTED
# client closed the socket even before accept # client closed the socket even before accept
client.close rescue nil client.close rescue nil
rescue Object => exc rescue Object => e
STDERR.puts "** Unhandled exception #{exc.inspect}." STDERR.puts "#{Time.now}: Unhandled listen loop exception #{e.inspect}."
STDERR.puts $!.backtrace.join("\n") STDERR.puts e.backtrace.join("\n")
end end
end end
graceful_shutdown graceful_shutdown
Expand Down
112 changes: 58 additions & 54 deletions test/testhelp.rb
Expand Up @@ -4,63 +4,67 @@
# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html # Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html
# for more information. # for more information.


HERE = File.dirname(__FILE__) unless defined? $require_once
%w(lib ext bin test).each do |dir|
$LOAD_PATH.unshift "#{HERE}/../#{dir}"
end

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 $require_once = true
orig_err = STDERR.dup
orig_out = STDOUT.dup
STDERR.reopen("test_stderr.log")
STDOUT.reopen("test_stdout.log")


begin HERE = File.dirname(__FILE__)
yield %w(lib ext bin test).each do |dir|
ensure $LOAD_PATH.unshift "#{HERE}/../#{dir}"
STDERR.reopen(orig_err)
STDOUT.reopen(orig_out)
end end
end

require 'rubygems'

require 'test/unit'
# Either takes a string to do a get request against, or a tuple of [URI, HTTP] where require 'net/http'
# HTTP is some kind of Net::HTTP request object (POST, HEAD, etc.) require 'timeout'
def hit(uris) require 'cgi/session'
results = [] require 'fileutils'
uris.each do |u| require 'benchmark'
res = nil require 'digest/sha1'

require 'uri'
if u.kind_of? String require 'stringio'
res = Net::HTTP.get(URI.parse(u))
else require 'mongrel'
url = URI.parse(u[0]) require 'mongrel/stats'
res = Net::HTTP.new(url.host, url.port).start {|h| h.request(u[1]) }
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 end

assert res != nil, "Didn't get a response: #{u}"
results << res
end 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 end

4 changes: 2 additions & 2 deletions tools/trickletest.rb
Expand Up @@ -18,8 +18,8 @@ def do_test(st, chunk)
break break
end end
end end
rescue Object rescue Object => e
STDERR.puts "ERROR: #$!" STDERR.puts "ERROR: #{e}"
ensure ensure
s.close s.close
end end
Expand Down

0 comments on commit f0f0e74

Please sign in to comment.