2009-10-15 16:23:29 +00:00
|
|
|
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
|
|
|
require 'mongo'
|
|
|
|
require 'test/unit'
|
|
|
|
|
|
|
|
# NOTE: these tests are run only if we can connect to a single MongoDB in slave mode.
|
|
|
|
class SlaveConnectionTest < Test::Unit::TestCase
|
|
|
|
include Mongo
|
|
|
|
|
|
|
|
def self.connect_to_slave
|
|
|
|
@@host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
|
|
|
@@port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
|
2009-11-23 20:20:05 +00:00
|
|
|
conn = Connection.new(@@host, @@port, :slave_ok => true)
|
|
|
|
!conn.master?
|
2009-10-15 16:23:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if self.connect_to_slave
|
|
|
|
puts "Connected to slave; running slave tests."
|
|
|
|
|
|
|
|
def test_connect_to_slave
|
|
|
|
assert_raise Mongo::ConfigurationError do
|
|
|
|
@db = Connection.new(@@host, @@port, :slave_ok => false).db('ruby-mongo-demo')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_slave_ok_sent_to_queries
|
|
|
|
@db = Connection.new(@@host, @@port, :slave_ok => true).db('ruby-mongo-demo')
|
2009-10-22 18:10:12 +00:00
|
|
|
assert_equal true, @db.slave_ok?
|
2009-10-15 16:23:29 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
puts "Not connected to slave; skipping slave connection tests."
|
|
|
|
|
|
|
|
def test_slave_ok_false_on_queries
|
2009-11-23 20:20:05 +00:00
|
|
|
@conn = Connection.new(@@host, @@port)
|
|
|
|
assert !@conn.slave_ok?
|
2009-10-15 16:23:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|