mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge branch 'master' into testing
This commit is contained in:
commit
ace9e533dc
4 changed files with 66 additions and 8 deletions
46
actionpack/test/controller/logging_test.rb
Normal file
46
actionpack/test/controller/logging_test.rb
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
require 'abstract_unit'
|
||||||
|
|
||||||
|
class LoggingController < ActionController::Base
|
||||||
|
def show
|
||||||
|
render :nothing => true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class LoggingTest < ActionController::TestCase
|
||||||
|
tests LoggingController
|
||||||
|
|
||||||
|
class MockLogger
|
||||||
|
attr_reader :logged
|
||||||
|
|
||||||
|
def method_missing(method, *args)
|
||||||
|
@logged ||= []
|
||||||
|
@logged << args.first
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
setup :set_logger
|
||||||
|
|
||||||
|
def test_logging_without_parameters
|
||||||
|
get :show
|
||||||
|
assert_equal 2, logs.size
|
||||||
|
assert_nil logs.detect {|l| l =~ /Parameters/ }
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_logging_with_parameters
|
||||||
|
get :show, :id => 10
|
||||||
|
assert_equal 3, logs.size
|
||||||
|
|
||||||
|
params = logs.detect {|l| l =~ /Parameters/ }
|
||||||
|
assert_equal 'Parameters: {"id"=>"10"}', params
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def set_logger
|
||||||
|
@controller.logger = MockLogger.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def logs
|
||||||
|
@logs ||= @controller.logger.logged.compact.map {|l| l.strip}
|
||||||
|
end
|
||||||
|
end
|
|
@ -65,15 +65,23 @@ module ActiveRecord
|
||||||
# The default ConnectionPool maximum size is 5.
|
# The default ConnectionPool maximum size is 5.
|
||||||
def initialize(spec)
|
def initialize(spec)
|
||||||
@spec = spec
|
@spec = spec
|
||||||
|
|
||||||
# The cache of reserved connections mapped to threads
|
# The cache of reserved connections mapped to threads
|
||||||
@reserved_connections = {}
|
@reserved_connections = {}
|
||||||
|
|
||||||
# The mutex used to synchronize pool access
|
# The mutex used to synchronize pool access
|
||||||
@connection_mutex = Monitor.new
|
@connection_mutex = Monitor.new
|
||||||
@queue = @connection_mutex.new_cond
|
@queue = @connection_mutex.new_cond
|
||||||
# default 5 second timeout
|
|
||||||
@timeout = spec.config[:wait_timeout] || 5
|
# default 5 second timeout unless on ruby 1.9
|
||||||
|
@timeout =
|
||||||
|
if RUBY_VERSION < '1.9'
|
||||||
|
spec.config[:wait_timeout] || 5
|
||||||
|
end
|
||||||
|
|
||||||
# default max pool size to 5
|
# default max pool size to 5
|
||||||
@size = (spec.config[:pool] && spec.config[:pool].to_i) || 5
|
@size = (spec.config[:pool] && spec.config[:pool].to_i) || 5
|
||||||
|
|
||||||
@connections = []
|
@connections = []
|
||||||
@checked_out = []
|
@checked_out = []
|
||||||
end
|
end
|
||||||
|
@ -187,7 +195,7 @@ module ActiveRecord
|
||||||
# try looting dead threads
|
# try looting dead threads
|
||||||
clear_stale_cached_connections!
|
clear_stale_cached_connections!
|
||||||
if @size == @checked_out.size
|
if @size == @checked_out.size
|
||||||
raise ConnectionTimeoutError, "could not obtain a database connection within #{@timeout} seconds. The pool size is currently #{@size}, perhaps you need to increase it?"
|
raise ConnectionTimeoutError, "could not obtain a database connection#{" within #{@timeout} seconds" if @timeout}. The max pool size is currently #{@size}; consider increasing it."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,10 +28,13 @@ class PooledConnectionsTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_pooled_connection_checkout
|
# Will deadlock due to lack of Monitor timeouts in 1.9
|
||||||
checkout_connections
|
if RUBY_VERSION < '1.9'
|
||||||
assert_equal @connections.length, 2
|
def test_pooled_connection_checkout
|
||||||
assert_equal @timed_out, 2
|
checkout_connections
|
||||||
|
assert_equal @connections.length, 2
|
||||||
|
assert_equal @timed_out, 2
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def checkout_checkin_connections(pool_size, threads)
|
def checkout_checkin_connections(pool_size, threads)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
require 'rake/testtask'
|
require 'rake/testtask'
|
||||||
require 'rake/rdoctask'
|
require 'rake/rdoctask'
|
||||||
require 'rake/gempackagetask'
|
require 'rake/gempackagetask'
|
||||||
require 'rake/contrib/sshpublisher'
|
|
||||||
|
|
||||||
require File.join(File.dirname(__FILE__), 'lib', 'active_support', 'version')
|
require File.join(File.dirname(__FILE__), 'lib', 'active_support', 'version')
|
||||||
|
|
||||||
|
@ -65,12 +64,14 @@ end
|
||||||
|
|
||||||
desc "Publish the beta gem"
|
desc "Publish the beta gem"
|
||||||
task :pgem => [:package] do
|
task :pgem => [:package] do
|
||||||
|
require 'rake/contrib/sshpublisher'
|
||||||
Rake::SshFilePublisher.new("gems.rubyonrails.org", "/u/sites/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
|
Rake::SshFilePublisher.new("gems.rubyonrails.org", "/u/sites/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
|
||||||
`ssh gems.rubyonrails.org '/u/sites/gems/gemupdate.sh'`
|
`ssh gems.rubyonrails.org '/u/sites/gems/gemupdate.sh'`
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Publish the API documentation"
|
desc "Publish the API documentation"
|
||||||
task :pdoc => [:rdoc] do
|
task :pdoc => [:rdoc] do
|
||||||
|
require 'rake/contrib/sshpublisher'
|
||||||
Rake::SshDirPublisher.new("wrath.rubyonrails.org", "public_html/as", "doc").upload
|
Rake::SshDirPublisher.new("wrath.rubyonrails.org", "public_html/as", "doc").upload
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue