RUBY-236 more timeout tweaks and tests

This commit is contained in:
Kyle Banker 2011-03-29 11:46:29 -04:00
parent 017d252689
commit a6cc09e50c
3 changed files with 8 additions and 4 deletions

View File

@ -80,11 +80,14 @@ require 'mongo/gridfs/grid_file_system'
if !defined?(RUBY_ENGINE) || (RUBY_ENGINE == 'ruby' && RUBY_VERSION < '1.9.0')
begin
require 'system_timer'
if SystemTimer.method(:timeout).arity.abs != 2
raise LoadError
end
Mongo::TimeoutHandler = SystemTimer
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. " +
"See http://ph7spot.com/musings/system-timer for details."
"See http://ph7spot.com/blog/system-timer-1-2-release for details."
require 'timeout'
Mongo::TimeoutHandler = Timeout
end

View File

@ -838,6 +838,7 @@ module Mongo
def receive_message_on_socket(length, socket)
begin
if @op_timeout
message = nil
Mongo::TimeoutHandler.timeout(@op_timeout, OperationTimeout) do
message = receive_data(length, socket)
end
@ -848,7 +849,7 @@ module Mongo
close
if ex.class == OperationTimeout
raise OperationTimeout, "Timed out waiting in socket read."
raise OperationTimeout, "Timed out waiting on socket read."
else
raise ConnectionFailure, "Operation failed with the following exception: #{ex}"
end

View File

@ -1,7 +1,7 @@
require './test/test_helper'
class TestCollection < Test::Unit::TestCase
@@connection ||= standard_connection
@@connection ||= standard_connection(:op_timeout => 2)
@@db = @@connection.db(MONGO_TEST_DB)
@@test = @@db.collection("test")
@@version = @@connection.server_version