Sha256: 90f9bfb07e797e7a60c6f63db61b3254ef7ae42ce074d0d13cf49c05a5ef3817

Contents?: true

Size: 1.11 KB

Versions: 20

Compression:

Stored size: 1.11 KB

Contents

require 'test/test_helper'

# 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
    conn = Connection.new(@@host, @@port, :slave_ok => true)
    cmd = conn['admin'].command(:ismaster => 1)
    cmd['ok'] == 1 && cmd['ismaster'] != 1
  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')
      assert_equal true, @db.slave_ok?
    end
  else
    puts "Not connected to slave; skipping slave connection tests."

    def test_slave_ok_false_on_queries
      @conn = Connection.new(@@host, @@port)
      assert !@conn.slave_ok?
    end
  end
end

Version data entries

20 entries across 20 versions & 3 rubygems

Version Path
mongo-1.0.6 test/slave_connection_test.rb
mongo-1.0.5 test/slave_connection_test.rb
mongo-1.0.4 test/slave_connection_test.rb
mongo-1.0.3 test/slave_connection_test.rb
mongo-1.0.2 test/slave_connection_test.rb
mongo-1.0.1 test/slave_connection_test.rb
mongo-1.0 test/slave_connection_test.rb
mongo-0.20.1 test/slave_connection_test.rb
mongo-0.20 test/slave_connection_test.rb
mongo-0.19.3 test/slave_connection_test.rb
mongo-0.19.2 test/slave_connection_test.rb
mongo-0.19.1 test/slave_connection_test.rb
mongo-0.19 test/slave_connection_test.rb
kbaum-mongo-0.19 test/slave_connection_test.rb
kbaum-mongo-0.18.3.2 test/slave_connection_test.rb
kbaum-mongo-0.18.3p test/slave_connection_test.rb
mongo-find_replace-0.18.3 test/test_slave_connection.rb
mongo-0.18.3 test/test_slave_connection.rb
mongo-0.18.2 test/test_slave_connection.rb
mongo-0.18.1 test/test_slave_connection.rb