1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
# frozen_string_literal: true
require_relative "helper"
class TestErrorReplies < Minitest::Test
include Helper::Client
# Every test shouldn't disconnect from the server. Also, when error replies are
# in play, the protocol should never get into an invalid state where there are
# pending replies in the connection. Calling INFO after every test ensures that
# the protocol is still in a valid state.
def with_reconnection_check
before = r.info["total_connections_received"]
yield(r)
after = r.info["total_connections_received"]
ensure
assert_equal before, after
end
def test_error_reply_for_single_command
with_reconnection_check do
begin
r.unknown_command
rescue => ex
ensure
assert ex.message =~ /unknown command/i
end
end
end
def test_raise_first_error_reply_in_pipeline
with_reconnection_check do
begin
r.pipelined do
r.set("foo", "s1")
r.incr("foo") # not an integer
r.lpush("foo", "value") # wrong kind of value
end
rescue => ex
ensure
assert ex.message =~ /not an integer/i
end
end
end
def test_recover_from_raise_in__call_loop
with_reconnection_check do
begin
r._client.call_loop([:invalid_monitor]) do
assert false # Should never be executed
end
rescue => ex
ensure
assert ex.message =~ /unknown command/i
end
end
end
end
|