Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

minor test cleanups

git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@710 19e92222-5c0b-0410-8929-a290d50e31e9
  • Loading branch information...
commit c60ff81f1ed1efe7f03fc31cf4c566264f3e314a 1 parent 0320048
evanweaver authored
Showing with 79 additions and 68 deletions.
  1. +19 −12 lib/mongrel.rb
  2. +58 −54 test/testhelp.rb
  3. +2 −2 tools/trickletest.rb
View
31 lib/mongrel.rb
@@ -266,9 +266,9 @@ def read_body(remain, total)
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 @@ def process_client(client)
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 @@ def run
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
112 test/testhelp.rb
@@ -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
-
-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
+unless defined? $require_once
-def redirect_test_io
- orig_err = STDERR.dup
- orig_out = STDOUT.dup
- STDERR.reopen("test_stderr.log")
- STDOUT.reopen("test_stdout.log")
+ $require_once = true
- 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
4 tools/trickletest.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.