RUBY-236 more timeout tweaks and tests
This commit is contained in:
parent
017d252689
commit
a6cc09e50c
|
@ -80,11 +80,14 @@ require 'mongo/gridfs/grid_file_system'
|
||||||
if !defined?(RUBY_ENGINE) || (RUBY_ENGINE == 'ruby' && RUBY_VERSION < '1.9.0')
|
if !defined?(RUBY_ENGINE) || (RUBY_ENGINE == 'ruby' && RUBY_VERSION < '1.9.0')
|
||||||
begin
|
begin
|
||||||
require 'system_timer'
|
require 'system_timer'
|
||||||
|
if SystemTimer.method(:timeout).arity.abs != 2
|
||||||
|
raise LoadError
|
||||||
|
end
|
||||||
Mongo::TimeoutHandler = SystemTimer
|
Mongo::TimeoutHandler = SystemTimer
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
warn "Could not load SystemTimer gem. Falling back to timeout.rb. " +
|
warn "Could not load SystemTimer >= v1.2.0. Falling back to timeout.rb. " +
|
||||||
"SystemTimer is STRONGLY recommended for timeouts in Ruby 1.8.7. " +
|
"SystemTimer is STRONGLY recommended for timeouts in Ruby 1.8.7. " +
|
||||||
"See http://ph7spot.com/musings/system-timer for details."
|
"See http://ph7spot.com/blog/system-timer-1-2-release for details."
|
||||||
require 'timeout'
|
require 'timeout'
|
||||||
Mongo::TimeoutHandler = Timeout
|
Mongo::TimeoutHandler = Timeout
|
||||||
end
|
end
|
||||||
|
|
|
@ -838,6 +838,7 @@ module Mongo
|
||||||
def receive_message_on_socket(length, socket)
|
def receive_message_on_socket(length, socket)
|
||||||
begin
|
begin
|
||||||
if @op_timeout
|
if @op_timeout
|
||||||
|
message = nil
|
||||||
Mongo::TimeoutHandler.timeout(@op_timeout, OperationTimeout) do
|
Mongo::TimeoutHandler.timeout(@op_timeout, OperationTimeout) do
|
||||||
message = receive_data(length, socket)
|
message = receive_data(length, socket)
|
||||||
end
|
end
|
||||||
|
@ -848,7 +849,7 @@ module Mongo
|
||||||
close
|
close
|
||||||
|
|
||||||
if ex.class == OperationTimeout
|
if ex.class == OperationTimeout
|
||||||
raise OperationTimeout, "Timed out waiting in socket read."
|
raise OperationTimeout, "Timed out waiting on socket read."
|
||||||
else
|
else
|
||||||
raise ConnectionFailure, "Operation failed with the following exception: #{ex}"
|
raise ConnectionFailure, "Operation failed with the following exception: #{ex}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require './test/test_helper'
|
require './test/test_helper'
|
||||||
|
|
||||||
class TestCollection < Test::Unit::TestCase
|
class TestCollection < Test::Unit::TestCase
|
||||||
@@connection ||= standard_connection
|
@@connection ||= standard_connection(:op_timeout => 2)
|
||||||
@@db = @@connection.db(MONGO_TEST_DB)
|
@@db = @@connection.db(MONGO_TEST_DB)
|
||||||
@@test = @@db.collection("test")
|
@@test = @@db.collection("test")
|
||||||
@@version = @@connection.server_version
|
@@version = @@connection.server_version
|
||||||
|
|
Loading…
Reference in New Issue