Skip to content

Commit

Permalink
Remove driver conditionals in tests
Browse files Browse the repository at this point in the history
Now that synchrony is gone and hiredis support SSL
we don't need to single out some drivers.
  • Loading branch information
byroot committed Aug 17, 2022
1 parent d3a9366 commit ebce34d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 77 deletions.
4 changes: 0 additions & 4 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@
ENV['REDIS_SOCKET_PATH'] = sock_file
end

def driver(*drivers, &blk)
class_eval(&blk) if drivers.map(&:to_s).include?(ENV["DRIVER"])
end

Dir[File.expand_path('lint/**/*.rb', __dir__)].sort.each do |f|
require f
end
Expand Down
72 changes: 35 additions & 37 deletions test/redis/fork_safety_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,47 @@ def setup
skip("Fork unavailable") unless Process.respond_to?(:fork)
end

driver(:ruby, :hiredis) do
def test_fork_safety
redis = Redis.new(OPTIONS)
redis.set "foo", 1

child_pid = fork do
# InheritedError triggers a reconnect,
# so we need to disable reconnects to force
# the exception bubble up
redis.without_reconnect do
redis.set "foo", 2
end
exit! 0
rescue Redis::InheritedError
exit! 127
def test_fork_safety
redis = Redis.new(OPTIONS)
redis.set "foo", 1

child_pid = fork do
# InheritedError triggers a reconnect,
# so we need to disable reconnects to force
# the exception bubble up
redis.without_reconnect do
redis.set "foo", 2
end
exit! 0
rescue Redis::InheritedError
exit! 127
end

_, status = Process.wait2(child_pid)
_, status = Process.wait2(child_pid)

assert_equal 127, status.exitstatus
assert_equal "1", redis.get("foo")
end
assert_equal 127, status.exitstatus
assert_equal "1", redis.get("foo")
end

def test_fork_safety_with_enabled_inherited_socket
redis = Redis.new(OPTIONS.merge(inherit_socket: true))
redis.set "foo", 1

child_pid = fork do
# InheritedError triggers a reconnect,
# so we need to disable reconnects to force
# the exception bubble up
redis.without_reconnect do
redis.set "foo", 2
end
exit! 0
rescue Redis::InheritedError
exit! 127
def test_fork_safety_with_enabled_inherited_socket
redis = Redis.new(OPTIONS.merge(inherit_socket: true))
redis.set "foo", 1

child_pid = fork do
# InheritedError triggers a reconnect,
# so we need to disable reconnects to force
# the exception bubble up
redis.without_reconnect do
redis.set "foo", 2
end
exit! 0
rescue Redis::InheritedError
exit! 127
end

_, status = Process.wait2(child_pid)
_, status = Process.wait2(child_pid)

assert_equal 0, status.exitstatus
assert_equal "2", redis.get("foo")
end
assert_equal 0, status.exitstatus
assert_equal "2", redis.get("foo")
end
end
32 changes: 13 additions & 19 deletions test/redis/internals_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,16 @@ def test_connecting_to_unix_domain_socket
Redis.new(OPTIONS.merge(path: ENV.fetch("REDIS_SOCKET_PATH"))).ping
end

driver(:ruby, :hiredis) do
def test_bubble_timeout_without_retrying
serv = TCPServer.new(6380)
def test_bubble_timeout_without_retrying
serv = TCPServer.new(6380)

redis = Redis.new(port: 6380, timeout: 0.1)
redis = Redis.new(port: 6380, timeout: 0.1)

assert_raises(Redis::TimeoutError) do
redis.ping
end
ensure
serv&.close
assert_raises(Redis::TimeoutError) do
redis.ping
end
ensure
serv&.close
end

def test_client_options
Expand Down Expand Up @@ -282,19 +280,15 @@ def af_test(host)
redis_mock(commands, host: host, &:ping)
end

driver(:ruby) do
af_family_supported(Socket::AF_INET) do
def test_connect_ipv4
af_test("127.0.0.1")
end
af_family_supported(Socket::AF_INET) do
def test_connect_ipv4
af_test("127.0.0.1")
end
end

driver(:ruby) do
af_family_supported(Socket::AF_INET6) do
def test_connect_ipv6
af_test("::1")
end
af_family_supported(Socket::AF_INET6) do
def test_connect_ipv6
af_test("::1")
end
end

Expand Down
32 changes: 15 additions & 17 deletions test/redis/thread_safety_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,25 @@
class TestThreadSafety < Minitest::Test
include Helper::Client

driver(:ruby, :hiredis) do
def test_thread_safety
redis = Redis.new(OPTIONS)
redis.set "foo", 1
redis.set "bar", 2
def test_thread_safety
redis = Redis.new(OPTIONS)
redis.set "foo", 1
redis.set "bar", 2

sample = 100
sample = 100

t1 = Thread.new do
@foos = Array.new(sample) { redis.get "foo" }
end
t1 = Thread.new do
@foos = Array.new(sample) { redis.get "foo" }
end

t2 = Thread.new do
@bars = Array.new(sample) { redis.get "bar" }
end
t2 = Thread.new do
@bars = Array.new(sample) { redis.get "bar" }
end

t1.join
t2.join
t1.join
t2.join

assert_equal ["1"], @foos.uniq
assert_equal ["2"], @bars.uniq
end
assert_equal ["1"], @foos.uniq
assert_equal ["2"], @bars.uniq
end
end

0 comments on commit ebce34d

Please sign in to comment.