spec/client_spec.rb in redis_failover-0.5.2 vs spec/client_spec.rb in redis_failover-0.5.3

- old
+ new

@@ -17,11 +17,13 @@ :slaves => ['localhost:1111'], :unavailable => [] } end - def setup_zookeeper_client; end + def setup_zookeeper_client + update_znode_timestamp + end end describe Client do let(:client) { ClientStub.new(:zkservers => 'localhost:9281') } @@ -35,18 +37,26 @@ end end describe '#dispatch' do it 'routes write operations to master' do - client.current_master.should_receive(:del) + called = false + client.current_master.define_singleton_method(:del) do |*args| + called = true + end client.del('foo') + called.should be_true end it 'routes read operations to a slave' do + called = false client.current_slaves.first.change_role_to('slave') - client.current_slaves.first.should_receive(:get) + client.current_slaves.first.define_singleton_method(:get) do |*args| + called = true + end client.get('foo') + called.should be_true end it 'reconnects when node is unavailable' do class << client attr_reader :reconnected @@ -75,9 +85,14 @@ expect { client.send(:master) }.to raise_error(InvalidNodeRoleError) end it 'raises error for unsupported operations' do expect { client.select }.to raise_error(UnsupportedOperationError) + end + + it 'raises error when no communication from Node Manager within certain time window' do + client.instance_variable_set(:@last_znode_timestamp, Time.at(0)) + expect { client.del('foo') }.to raise_error(MissingNodeManagerError) end end end end