File: error_replies_test.rb

package info (click to toggle)
ruby-redis 3.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 736 kB
  • ctags: 1,128
  • sloc: ruby: 8,149; makefile: 5
file content (59 lines) | stat: -rw-r--r-- 1,508 bytes parent folder | download | duplicates (3)
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
59
# encoding: UTF-8

require File.expand_path("helper", File.dirname(__FILE__))

class TestErrorReplies < Test::Unit::TestCase

  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