Skip to content

Commit

Permalink
Assume Redis 5+
Browse files Browse the repository at this point in the history
Even 5.0 is EOL, and it's the oldest version we test against,
so no point keeping all these version checks.
  • Loading branch information
byroot committed Aug 12, 2022
1 parent 12497e6 commit a95c629
Show file tree
Hide file tree
Showing 28 changed files with 865 additions and 1,150 deletions.
6 changes: 2 additions & 4 deletions test/cluster/client_key_hash_tags_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,8 @@ def test_whether_the_command_effect_is_readonly_or_not
assert_equal false, described_class.should_send_to_master?([:get])
assert_equal true, described_class.should_send_to_slave?([:get])

target_version('3.2.0') do
assert_equal false, described_class.should_send_to_master?([:info])
assert_equal false, described_class.should_send_to_slave?([:info])
end
assert_equal false, described_class.should_send_to_master?([:info])
assert_equal false, described_class.should_send_to_slave?([:info])
end

def test_cannot_build_details_from_bad_urls
Expand Down
62 changes: 24 additions & 38 deletions test/cluster/commands_on_geo_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,68 +7,54 @@
class TestClusterCommandsOnGeo < Minitest::Test
include Helper::Cluster

MIN_REDIS_VERSION = '3.2.0'

def add_sicily
redis.geoadd('Sicily',
13.361389, 38.115556, 'Palermo',
15.087269, 37.502669, 'Catania')
end

def test_geoadd
target_version(MIN_REDIS_VERSION) do
assert_equal 2, add_sicily
end
assert_equal 2, add_sicily
end

def test_geohash
target_version(MIN_REDIS_VERSION) do
add_sicily
assert_equal %w[sqc8b49rny0 sqdtr74hyu0], redis.geohash('Sicily', %w[Palermo Catania])
end
add_sicily
assert_equal %w[sqc8b49rny0 sqdtr74hyu0], redis.geohash('Sicily', %w[Palermo Catania])
end

def test_geopos
target_version(MIN_REDIS_VERSION) do
add_sicily
expected = [%w[13.36138933897018433 38.11555639549629859],
%w[15.08726745843887329 37.50266842333162032],
nil]
assert_equal expected, redis.geopos('Sicily', %w[Palermo Catania NonExisting])
end
add_sicily
expected = [%w[13.36138933897018433 38.11555639549629859],
%w[15.08726745843887329 37.50266842333162032],
nil]
assert_equal expected, redis.geopos('Sicily', %w[Palermo Catania NonExisting])
end

def test_geodist
target_version(MIN_REDIS_VERSION) do
add_sicily
assert_equal '166274.1516', redis.geodist('Sicily', 'Palermo', 'Catania')
assert_equal '166.2742', redis.geodist('Sicily', 'Palermo', 'Catania', 'km')
assert_equal '103.3182', redis.geodist('Sicily', 'Palermo', 'Catania', 'mi')
end
add_sicily
assert_equal '166274.1516', redis.geodist('Sicily', 'Palermo', 'Catania')
assert_equal '166.2742', redis.geodist('Sicily', 'Palermo', 'Catania', 'km')
assert_equal '103.3182', redis.geodist('Sicily', 'Palermo', 'Catania', 'mi')
end

def test_georadius
target_version(MIN_REDIS_VERSION) do
add_sicily
add_sicily

expected = [%w[Palermo 190.4424], %w[Catania 56.4413]]
assert_equal expected, redis.georadius('Sicily', 15, 37, 200, 'km', 'WITHDIST')
expected = [%w[Palermo 190.4424], %w[Catania 56.4413]]
assert_equal expected, redis.georadius('Sicily', 15, 37, 200, 'km', 'WITHDIST')

expected = [['Palermo', %w[13.36138933897018433 38.11555639549629859]],
['Catania', %w[15.08726745843887329 37.50266842333162032]]]
assert_equal expected, redis.georadius('Sicily', 15, 37, 200, 'km', 'WITHCOORD')
expected = [['Palermo', %w[13.36138933897018433 38.11555639549629859]],
['Catania', %w[15.08726745843887329 37.50266842333162032]]]
assert_equal expected, redis.georadius('Sicily', 15, 37, 200, 'km', 'WITHCOORD')

expected = [['Palermo', '190.4424', %w[13.36138933897018433 38.11555639549629859]],
['Catania', '56.4413', %w[15.08726745843887329 37.50266842333162032]]]
assert_equal expected, redis.georadius('Sicily', 15, 37, 200, 'km', 'WITHDIST', 'WITHCOORD')
end
expected = [['Palermo', '190.4424', %w[13.36138933897018433 38.11555639549629859]],
['Catania', '56.4413', %w[15.08726745843887329 37.50266842333162032]]]
assert_equal expected, redis.georadius('Sicily', 15, 37, 200, 'km', 'WITHDIST', 'WITHCOORD')
end

def test_georadiusbymember
target_version(MIN_REDIS_VERSION) do
redis.geoadd('Sicily', 13.583333, 37.316667, 'Agrigento')
add_sicily
assert_equal %w[Agrigento Palermo], redis.georadiusbymember('Sicily', 'Agrigento', 100, 'km')
end
redis.geoadd('Sicily', 13.583333, 37.316667, 'Agrigento')
add_sicily
assert_equal %w[Agrigento Palermo], redis.georadiusbymember('Sicily', 'Agrigento', 100, 'km')
end
end
30 changes: 13 additions & 17 deletions test/cluster/commands_on_keys_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,29 +93,25 @@ def test_sort
end

def test_touch
target_version('3.2.1') do
set_some_keys
assert_equal 1, redis.touch('key1')
assert_equal 1, redis.touch('key2')
if version < '6'
assert_equal 1, redis.touch('key1', 'key2')
else
assert_raises(Redis::CommandError, "CROSSSLOT Keys in request don't hash to the same slot") do
redis.touch('key1', 'key2')
end
set_some_keys
assert_equal 1, redis.touch('key1')
assert_equal 1, redis.touch('key2')
if version < '6'
assert_equal 1, redis.touch('key1', 'key2')
else
assert_raises(Redis::CommandError, "CROSSSLOT Keys in request don't hash to the same slot") do
redis.touch('key1', 'key2')
end
assert_equal 2, redis.touch('{key}1', '{key}2')
end
assert_equal 2, redis.touch('{key}1', '{key}2')
end

def test_unlink
target_version('4.0.0') do
set_some_keys
assert_raises(Redis::CommandError, "CROSSSLOT Keys in request don't hash to the same slot") do
redis.unlink('key1', 'key2', 'key3')
end
assert_equal 2, redis.unlink('{key}1', '{key}2', '{key}3')
set_some_keys
assert_raises(Redis::CommandError, "CROSSSLOT Keys in request don't hash to the same slot") do
redis.unlink('key1', 'key2', 'key3')
end
assert_equal 2, redis.unlink('{key}1', '{key}2', '{key}3')
end

def test_wait
Expand Down
6 changes: 2 additions & 4 deletions test/cluster/commands_on_scripting_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ def test_evalsha
end

def test_script_debug
target_version('3.2.0') do
assert_equal 'OK', redis.script(:debug, 'yes')
assert_equal 'OK', redis.script(:debug, 'no')
end
assert_equal 'OK', redis.script(:debug, 'yes')
assert_equal 'OK', redis.script(:debug, 'no')
end

def test_script_exists
Expand Down
30 changes: 8 additions & 22 deletions test/cluster/commands_on_server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def test_client_pause
end

def test_client_reply
target_version('3.2.0') do
assert_equal 'OK', redis.client(:reply, 'ON')
end
assert_equal 'OK', redis.client(:reply, 'ON')
end

def test_client_setname
Expand Down Expand Up @@ -143,40 +141,28 @@ def test_lastsave
end

def test_memory_doctor
target_version('4.0.0') do
assert_instance_of String, redis.memory(:doctor)
end
assert_instance_of String, redis.memory(:doctor)
end

def test_memory_help
target_version('4.0.0') do
assert_instance_of Array, redis.memory(:help)
end
assert_instance_of Array, redis.memory(:help)
end

def test_memory_malloc_stats
target_version('4.0.0') do
assert_instance_of String, redis.memory('malloc-stats')
end
assert_instance_of String, redis.memory('malloc-stats')
end

def test_memory_purge
target_version('4.0.0') do
assert_equal 'OK', redis.memory(:purge)
end
assert_equal 'OK', redis.memory(:purge)
end

def test_memory_stats
target_version('4.0.0') do
assert_instance_of Array, redis.memory(:stats)
end
assert_instance_of Array, redis.memory(:stats)
end

def test_memory_usage
target_version('4.0.0') do
redis.set('key1', 'Hello World')
assert_operator redis.memory(:usage, 'key1'), :>, 0
end
redis.set('key1', 'Hello World')
assert_operator redis.memory(:usage, 'key1'), :>, 0
end

def test_monitor
Expand Down
16 changes: 6 additions & 10 deletions test/distributed/commands_on_hyper_log_log_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@ class TestDistributedCommandsOnHyperLogLog < Minitest::Test
include Lint::HyperLogLog

def test_pfmerge
target_version '2.8.9' do
assert_raises Redis::Distributed::CannotDistribute do
super
end
assert_raises Redis::Distributed::CannotDistribute do
super
end
end

def test_pfcount_multiple_keys_diff_nodes
target_version '2.8.9' do
assert_raises Redis::Distributed::CannotDistribute do
r.pfadd 'foo', 's1'
r.pfadd 'bar', 's2'
assert_raises Redis::Distributed::CannotDistribute do
r.pfadd 'foo', 's1'
r.pfadd 'bar', 's2'

assert r.pfcount('res', 'foo', 'bar')
end
assert r.pfcount('res', 'foo', 'bar')
end
end
end
10 changes: 4 additions & 6 deletions test/distributed/commands_on_strings_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,11 @@ def test_msetnx_mapped
end

def test_bitop
target_version "2.5.10" do
assert_raises Redis::Distributed::CannotDistribute do
r.set("foo", "a")
r.set("bar", "b")
assert_raises Redis::Distributed::CannotDistribute do
r.set("foo", "a")
r.set("bar", "b")

r.bitop(:and, "foo&bar", "foo", "bar")
end
r.bitop(:and, "foo&bar", "foo", "bar")
end
end

Expand Down
36 changes: 16 additions & 20 deletions test/distributed/commands_on_value_types_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,35 @@ def test_del_with_array_argument
end

def test_unlink
target_version "4.0.0" do
r.set "foo", "s1"
r.set "bar", "s2"
r.set "baz", "s3"
r.set "foo", "s1"
r.set "bar", "s2"
r.set "baz", "s3"

assert_equal ["bar", "baz", "foo"], r.keys("*").sort
assert_equal ["bar", "baz", "foo"], r.keys("*").sort

assert_equal 1, r.unlink("foo")
assert_equal 1, r.unlink("foo")

assert_equal ["bar", "baz"], r.keys("*").sort
assert_equal ["bar", "baz"], r.keys("*").sort

assert_equal 2, r.unlink("bar", "baz")
assert_equal 2, r.unlink("bar", "baz")

assert_equal [], r.keys("*").sort
end
assert_equal [], r.keys("*").sort
end

def test_unlink_with_array_argument
target_version "4.0.0" do
r.set "foo", "s1"
r.set "bar", "s2"
r.set "baz", "s3"
r.set "foo", "s1"
r.set "bar", "s2"
r.set "baz", "s3"

assert_equal ["bar", "baz", "foo"], r.keys("*").sort
assert_equal ["bar", "baz", "foo"], r.keys("*").sort

assert_equal 1, r.unlink(["foo"])
assert_equal 1, r.unlink(["foo"])

assert_equal ["bar", "baz"], r.keys("*").sort
assert_equal ["bar", "baz"], r.keys("*").sort

assert_equal 2, r.unlink(["bar", "baz"])
assert_equal 2, r.unlink(["bar", "baz"])

assert_equal [], r.keys("*").sort
end
assert_equal [], r.keys("*").sort
end

def test_randomkey
Expand Down
24 changes: 11 additions & 13 deletions test/distributed/commands_requiring_clustering_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,16 @@ def test_sort_with_store
end

def test_bitop
target_version "2.5.10" do
r.set("{qux}foo", "a")
r.set("{qux}bar", "b")

r.bitop(:and, "{qux}foo&bar", "{qux}foo", "{qux}bar")
assert_equal "\x60", r.get("{qux}foo&bar")
r.bitop(:or, "{qux}foo|bar", "{qux}foo", "{qux}bar")
assert_equal "\x63", r.get("{qux}foo|bar")
r.bitop(:xor, "{qux}foo^bar", "{qux}foo", "{qux}bar")
assert_equal "\x03", r.get("{qux}foo^bar")
r.bitop(:not, "{qux}~foo", "{qux}foo")
assert_equal "\x9E", r.get("{qux}~foo")
end
r.set("{qux}foo", "a")
r.set("{qux}bar", "b")

r.bitop(:and, "{qux}foo&bar", "{qux}foo", "{qux}bar")
assert_equal "\x60", r.get("{qux}foo&bar")
r.bitop(:or, "{qux}foo|bar", "{qux}foo", "{qux}bar")
assert_equal "\x63", r.get("{qux}foo|bar")
r.bitop(:xor, "{qux}foo^bar", "{qux}foo", "{qux}bar")
assert_equal "\x03", r.get("{qux}foo^bar")
r.bitop(:not, "{qux}~foo", "{qux}foo")
assert_equal "\x9E", r.get("{qux}~foo")
end
end
30 changes: 13 additions & 17 deletions test/distributed/remote_server_control_commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@ def test_info
end

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

r.info(:commandstats).each do |info|
assert_equal '2', info['get']['calls']
end
r.info(:commandstats).each do |info|
assert_equal '2', info['get']['calls']
end
end

Expand All @@ -52,15 +50,13 @@ def test_echo
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)
# 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
assert((ruby_usec - redis_usec).abs < 500_000)
end
end
end
Loading

0 comments on commit a95c629

Please sign in to comment.