2010-12-14 18:14:45 +00:00
|
|
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
|
require './test/test_helper'
|
|
|
|
require './test/tools/repl_set_manager'
|
|
|
|
|
2012-01-30 00:05:17 +00:00
|
|
|
class Test::Unit::TestCase
|
|
|
|
# Ensure replica set is available as an instance variable and that
|
|
|
|
# a new set is spun up for each TestCase class
|
|
|
|
def ensure_rs
|
|
|
|
unless defined?(@@current_class) and @@current_class == self.class
|
|
|
|
@@current_class = self.class
|
|
|
|
@@rs = ReplSetManager.new
|
|
|
|
@@rs.start_set
|
2011-11-03 15:17:36 +00:00
|
|
|
end
|
2012-01-30 00:05:17 +00:00
|
|
|
@rs = @@rs
|
2011-11-03 15:17:36 +00:00
|
|
|
end
|
2010-12-14 18:14:45 +00:00
|
|
|
|
|
|
|
# Generic code for rescuing connection failures and retrying operations.
|
|
|
|
# This could be combined with some timeout functionality.
|
2011-08-25 15:27:58 +00:00
|
|
|
def rescue_connection_failure(max_retries=30)
|
2010-12-29 18:13:54 +00:00
|
|
|
retries = 0
|
|
|
|
begin
|
|
|
|
yield
|
|
|
|
rescue Mongo::ConnectionFailure => ex
|
2011-02-15 21:48:29 +00:00
|
|
|
puts "Rescue attempt #{retries}: from #{ex}"
|
2010-12-29 18:13:54 +00:00
|
|
|
retries += 1
|
|
|
|
raise ex if retries > max_retries
|
2011-08-25 15:27:58 +00:00
|
|
|
sleep(2)
|
2010-12-29 18:13:54 +00:00
|
|
|
retry
|
2010-12-14 18:14:45 +00:00
|
|
|
end
|
|
|
|
end
|
2012-02-18 23:29:52 +00:00
|
|
|
|
|
|
|
def build_seeds(num_hosts)
|
|
|
|
seeds = []
|
|
|
|
num_hosts.times do |n|
|
|
|
|
seeds << "#{@rs.host}:#{@rs.ports[n]}"
|
|
|
|
end
|
|
|
|
seeds
|
|
|
|
end
|
2010-12-14 18:14:45 +00:00
|
|
|
end
|