Sha256: cab1afccb215ecbc9ae08f4827ebd4e83c9d26418c399e29ff9639f8b0ef8972

Contents?: true

Size: 1.98 KB

Versions: 4

Compression:

Stored size: 1.98 KB

Contents

require 'spec_helper'

module RedisFailover
  describe NodeManager do
    let(:manager) { NodeManagerStub.new({}) }

    describe '#nodes' do
      it 'returns current master and slave nodes' do
        manager.nodes.should == {
          :master => 'master:6379',
          :slaves => ['slave:6379'],
          :unreachable => []
        }
      end
    end

    describe '#handle_unreachable' do
      context 'slave dies' do
        it 'moves slave to unreachable list' do
          slave = manager.slaves.first
          manager.force_unreachable(slave)
          manager.nodes[:unreachable].should include(slave.to_s)
        end
      end

      context 'master dies' do
        before(:each) do
          @slave = manager.slaves.first
          @master = manager.master
          manager.force_unreachable(@master)
        end

        it 'promotes slave to master' do
          manager.master.should == @slave
        end

        it 'moves master to unreachable list' do
          manager.nodes[:unreachable].should include(@master.to_s)
        end
      end
    end

    describe '#handle_reachable' do
      before(:each) do
        # force to be unreachable first
        @slave = manager.slaves.first
        manager.force_unreachable(@slave)
      end

      context 'slave node with a master present' do
        it 'removes slave from unreachable list' do
          manager.force_reachable(@slave)
          manager.nodes[:unreachable].should be_empty
          manager.nodes[:slaves].should include(@slave.to_s)
        end
      end

      context 'slave node with no master present' do
        before(:each) do
          @master = manager.master
          manager.force_unreachable(@master)
        end

        it 'promotes slave to master' do
          manager.master.should be_nil
          manager.force_reachable(@slave)
          manager.master.should == @slave
        end

        it 'slaves list remains empty' do
          manager.nodes[:slaves].should be_empty
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
redis_failover-0.3.0 spec/node_manager_spec.rb
redis_failover-0.2.0 spec/node_manager_spec.rb
redis_failover-0.1.1 spec/node_manager_spec.rb
redis_failover-0.1.0 spec/node_manager_spec.rb