File: distributed_remote_server_control_commands_test.rb

package info (click to toggle)
ruby-redis 4.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,168 kB
  • sloc: ruby: 12,820; makefile: 107; sh: 24
file content (65 lines) | stat: -rw-r--r-- 1,489 bytes parent folder | download
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
60
61
62
63
64
65
# frozen_string_literal: true

require_relative "helper"

class TestDistributedRemoteServerControlCommands < Minitest::Test
  include Helper::Distributed

  def test_info
    keys = [
      "redis_version",
      "uptime_in_seconds",
      "uptime_in_days",
      "connected_clients",
      "used_memory",
      "total_connections_received",
      "total_commands_processed"
    ]

    infos = r.info

    infos.each do |info|
      keys.each do |k|
        msg = "expected #info to include #{k}"
        assert info.keys.include?(k), msg
      end
    end
  end

  def test_info_commandstats
    target_version "2.5.7" do
      r.nodes.each do |n|
        n.config(:resetstat)
        n.config(:get, :port)
      end

      r.info(:commandstats).each do |info|
        assert_equal '2', info['config']['calls'] # CONFIG RESETSTAT + CONFIG GET = twice
      end
    end
  end

  def test_monitor
    r.monitor
  rescue Exception => ex
  ensure
    assert ex.is_a?(NotImplementedError)
  end

  def test_echo
    assert_equal ["foo bar baz\n"], r.echo("foo bar baz\n")
  end

  def test_time
    target_version "2.5.4" do
      # Test that the difference between the time that Ruby reports and the time
      # that Redis reports is minimal (prevents the test from being racy).
      r.time.each do |rv|
        redis_usec = rv[0] * 1_000_000 + rv[1]
        ruby_usec = Integer(Time.now.to_f * 1_000_000)

        assert((ruby_usec - redis_usec).abs < 500_000)
      end
    end
  end
end