Sha256: 5f4ce5099832331d4999d0f0ce9bacfd90be003a4bdab440c865a19c181f270e

Contents?: true

Size: 1.61 KB

Versions: 6

Compression:

Stored size: 1.61 KB

Contents

require 'spec_helper'

module RedisFailover
  class LightNodeManager
    def initialize
      @node_states = {}
    end

    def notify_state_change(node, state)
      @node_states[node] = state
    end

    def state_for(node)
      @node_states[node]
    end
  end

  describe NodeWatcher do
    let(:node_manager) { LightNodeManager.new }
    let(:node) { Node.new(:host => 'host', :port => 123).extend(RedisStubSupport) }

    describe '#watch' do
      context 'node is not syncing with master' do
        it 'properly informs manager of unavailable node' do
          watcher = NodeWatcher.new(node_manager, node, 1)
          watcher.watch
          sleep(3)
          node.redis.make_unavailable!
          sleep(3)
          watcher.shutdown
          node_manager.state_for(node).should == :unavailable
        end

        it 'properly informs manager of available node' do
          node_manager.notify_state_change(node, :unavailable)
          watcher = NodeWatcher.new(node_manager, node, 1)
          watcher.watch
          sleep(3)
          watcher.shutdown
          node_manager.state_for(node).should == :available
        end
      end

      context 'node is syncing with master' do
        it 'properly informs manager of syncing node' do
          node_manager.notify_state_change(node, :unavailable)
          node.redis.slaveof('masterhost', 9876)
          node.redis.force_sync_with_master(true)
          watcher = NodeWatcher.new(node_manager, node, 1)
          watcher.watch
          sleep(3)
          watcher.shutdown
          node_manager.state_for(node).should == :syncing
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
redis_failover-0.5.4 spec/node_watcher_spec.rb
redis_failover-0.5.3 spec/node_watcher_spec.rb
redis_failover-0.5.2 spec/node_watcher_spec.rb
redis_failover-0.5.1 spec/node_watcher_spec.rb
redis_failover-0.5.0 spec/node_watcher_spec.rb
redis_failover-0.4.0 spec/node_watcher_spec.rb