spec/node_spec.rb in redis_failover-0.3.0 vs spec/node_spec.rb in redis_failover-0.4.0

- old
+ new

@@ -18,17 +18,17 @@ expect { Node.new }.to raise_error(InvalidNodeError) end end describe '#ping' do - it 'responds properly if node is reachable' do + it 'responds properly if node is available' do expect { node.ping }.to_not raise_error end - it 'responds properly if node is unreachable' do - node.redis.make_unreachable! - expect { node.ping }.to raise_error(NodeUnreachableError) + it 'responds properly if node is unavailable' do + node.redis.make_unavailable! + expect { node.ping }.to raise_error(NodeUnavailableError) end end describe '#master?' do it 'responds properly if node is master' do @@ -51,26 +51,34 @@ node.make_master! node.should be_master end end - describe '#wait_until_unreachable' do + describe '#wait' do it 'should wait until node dies' do - thread = Thread.new { node.wait_until_unreachable } + thread = Thread.new { node.wait } thread.should be_alive - node.redis.make_unreachable! + node.redis.make_unavailable! expect { thread.value }.to raise_error end end - describe '#stop_waiting' do + describe '#wakeup' do it 'should gracefully stop waiting' do - thread = Thread.new { node.wait_until_unreachable } + thread = Thread.new { node.wait } thread.should be_alive - node.stop_waiting + node.wakeup sleep 0.2 thread.should_not be_alive thread.value.should be_nil + end + end + + describe '#perform_operation' do + it 'raises error for any operation that hangs for too long' do + expect do + node.send(:perform_operation) { 1_000_000.times { sleep 0.1 } } + end.to raise_error(NodeUnavailableError) end end end end