test/internals_test.rb in redis-3.0.7 vs test/internals_test.rb in redis-3.1.0

- old
+ new

@@ -7,22 +7,22 @@ include Helper::Client def test_logger r.ping - assert log.string =~ /Redis >> PING/ - assert log.string =~ /Redis >> \d+\.\d+ms/ + assert log.string["[Redis] command=PING"] + assert log.string =~ /\[Redis\] call_time=\d+\.\d+ ms/ end def test_logger_with_pipelining r.pipelined do r.set "foo", "bar" r.get "foo" end - assert log.string["SET foo bar"] - assert log.string["GET foo"] + assert log.string[" command=SET args=\"foo\" \"bar\""] + assert log.string[" command=GET args=\"foo\""] end def test_recovers_from_failed_commands # See https://github.com/redis/redis-rb/issues#issue/28 @@ -155,11 +155,11 @@ assert_raise Redis::CannotConnectError do Redis.new(OPTIONS.merge(:host => "10.255.255.254", :timeout => 0.1)).ping end end - def close_on_ping(seq) + def close_on_ping(seq, options = {}) $request = 0 command = lambda do idx = $request $request += 1 @@ -167,11 +167,11 @@ rv = "+%d" % idx rv = nil if seq.include?(idx) rv end - redis_mock(:ping => command, :timeout => 0.1) do |redis| + redis_mock({:ping => command}, {:timeout => 0.1}.merge(options)) do |redis| yield(redis) end end def test_retry_by_default @@ -208,9 +208,25 @@ end end def test_retry_only_once_when_read_raises_econnreset close_on_ping([0, 1]) do |redis| + assert_raise Redis::ConnectionError do + redis.ping + end + + assert !redis.client.connected? + end + end + + def test_retry_with_custom_reconnect_attempts + close_on_ping([0, 1], :reconnect_attempts => 2) do |redis| + assert_equal "2", redis.ping + end + end + + def test_retry_with_custom_reconnect_attempts_can_still_fail + close_on_ping([0, 1, 2], :reconnect_attempts => 2) do |redis| assert_raise Redis::ConnectionError do redis.ping end assert !redis.client.connected?