add an option in connection to log duration

This commit is contained in:
Cyril Mougel 2012-02-03 17:29:30 +01:00
parent 99d9dfddfb
commit 6ab02373ea
2 changed files with 21 additions and 3 deletions

View File

@ -36,7 +36,7 @@ module Mongo
mongo_thread_local_accessor :connections
attr_reader :logger, :size, :auths, :primary, :safe, :host_to_try,
attr_reader :logger, :log_duration, :size, :auths, :primary, :safe, :host_to_try,
:pool_size, :connect_timeout, :pool_timeout,
:primary_pool, :socket_class, :op_timeout
@ -63,6 +63,8 @@ module Mongo
# to a single, slave node.
# @option opts [Logger, #debug] :logger (nil) A Logger instance for debugging driver ops. Note that
# logging negatively impacts performance; therefore, it should not be used for high-performance apps.
# @option opts [Boolean, #debug] :log_duration (nil) A boolean to say if you want see information about log_duration on logger
# like logging, log_duration negatively impacts performance; therefore, it should not be used for high-performance apps.
# @option opts [Integer] :pool_size (1) The maximum number of socket self.connections allowed per
# connection pool. Note: this setting is relevant only for multi-threaded applications.
# @option opts [Float] :pool_timeout (5.0) When all of the self.connections a pool are checked out,
@ -348,7 +350,7 @@ module Mongo
self["admin"].command(oh)
end
# Checks if a server is alive. This command will return immediately
# Checks if a server is alive. This command will return immediately
# even if the server is in a lock.
#
# @return [Hash]
@ -383,7 +385,7 @@ module Mongo
Thread.current[:socket_map] ||= {}
Thread.current[:socket_map][self] ||= {}
Thread.current[:socket_map][self][:writer] ||= checkout_writer
Thread.current[:socket_map][self][:reader] =
Thread.current[:socket_map][self][:reader] =
Thread.current[:socket_map][self][:writer]
end
@ -568,6 +570,7 @@ module Mongo
if @logger
write_logging_startup_message
@log_duration = opts[:log_duration] || false
end
should_connect = opts.fetch(:connect, true)

View File

@ -148,6 +148,21 @@ class TestConnection < Test::Unit::TestCase
assert output.string.include?('testing')
end
def test_connection_log_duration_with_logger
output = StringIO.new
logger = Logger.new(output)
logger.level = Logger::DEBUG
connection = standard_connection(:logger => logger, :log_duration => true)
assert logger, connection.logger
assert connection.log_duration
end
def test_connection_log_duration_without_logger
connection = standard_connection(:log_duration => true)
assert_nil connection.logger
assert !connection.log_duration
end
def test_drop_database
db = @conn.db('ruby-mongo-will-be-deleted')
coll = db.collection('temp')