2009-12-01 18:49:57 +00:00
|
|
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
|
require 'rubygems' if ENV['C_EXT']
|
2009-11-30 22:50:54 +00:00
|
|
|
require 'mongo'
|
2009-10-20 15:31:07 +00:00
|
|
|
require 'test/unit'
|
|
|
|
|
|
|
|
begin
|
2009-12-01 18:49:57 +00:00
|
|
|
require 'rubygems'
|
2010-02-22 20:49:04 +00:00
|
|
|
require 'shoulda'
|
2009-10-20 15:31:07 +00:00
|
|
|
require 'mocha'
|
|
|
|
rescue LoadError
|
|
|
|
puts <<MSG
|
|
|
|
|
2010-02-22 20:49:04 +00:00
|
|
|
This test suite requires shoulda and mocha.
|
|
|
|
You can install them as follows:
|
|
|
|
gem install shoulda
|
2009-10-20 15:31:07 +00:00
|
|
|
gem install mocha
|
|
|
|
|
|
|
|
MSG
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
2010-04-05 14:39:55 +00:00
|
|
|
require 'bson_ext/cbson' if ENV['C_EXT']
|
2009-12-01 18:49:57 +00:00
|
|
|
|
2009-10-20 15:31:07 +00:00
|
|
|
# NOTE: most tests assume that MongoDB is running.
|
|
|
|
class Test::Unit::TestCase
|
|
|
|
include Mongo
|
2010-04-05 14:39:55 +00:00
|
|
|
include BSON
|
2009-11-23 18:13:14 +00:00
|
|
|
|
|
|
|
# Generic code for rescuing connection failures and retrying operations.
|
|
|
|
# This could be combined with some timeout functionality.
|
|
|
|
def rescue_connection_failure
|
|
|
|
success = false
|
|
|
|
while !success
|
|
|
|
begin
|
|
|
|
yield
|
|
|
|
success = true
|
|
|
|
rescue Mongo::ConnectionFailure
|
|
|
|
puts "Rescuing"
|
|
|
|
sleep(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-10-20 15:31:07 +00:00
|
|
|
end
|