Skip to content

Commit 0dd4669

Browse files
committed
Remove driver conditionals in tests
Now that synchrony is gone and hiredis support SSL we don't need to single out some drivers.
1 parent 0c66db2 commit 0dd4669

File tree

4 files changed

+63
-77
lines changed

4 files changed

+63
-77
lines changed

test/helper.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@
3737
ENV['REDIS_SOCKET_PATH'] = sock_file
3838
end
3939

40-
def driver(*drivers, &blk)
41-
class_eval(&blk) if drivers.map(&:to_s).include?(ENV["DRIVER"])
42-
end
43-
4440
Dir[File.expand_path('lint/**/*.rb', __dir__)].sort.each do |f|
4541
require f
4642
end

test/redis/fork_safety_test.rb

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,47 @@ def setup
99
skip("Fork unavailable") unless Process.respond_to?(:fork)
1010
end
1111

12-
driver(:ruby, :hiredis) do
13-
def test_fork_safety
14-
redis = Redis.new(OPTIONS)
15-
redis.set "foo", 1
16-
17-
child_pid = fork do
18-
# InheritedError triggers a reconnect,
19-
# so we need to disable reconnects to force
20-
# the exception bubble up
21-
redis.without_reconnect do
22-
redis.set "foo", 2
23-
end
24-
exit! 0
25-
rescue Redis::InheritedError
26-
exit! 127
12+
def test_fork_safety
13+
redis = Redis.new(OPTIONS)
14+
redis.set "foo", 1
15+
16+
child_pid = fork do
17+
# InheritedError triggers a reconnect,
18+
# so we need to disable reconnects to force
19+
# the exception bubble up
20+
redis.without_reconnect do
21+
redis.set "foo", 2
2722
end
23+
exit! 0
24+
rescue Redis::InheritedError
25+
exit! 127
26+
end
2827

29-
_, status = Process.wait2(child_pid)
28+
_, status = Process.wait2(child_pid)
3029

31-
assert_equal 127, status.exitstatus
32-
assert_equal "1", redis.get("foo")
33-
end
30+
assert_equal 127, status.exitstatus
31+
assert_equal "1", redis.get("foo")
32+
end
3433

35-
def test_fork_safety_with_enabled_inherited_socket
36-
redis = Redis.new(OPTIONS.merge(inherit_socket: true))
37-
redis.set "foo", 1
38-
39-
child_pid = fork do
40-
# InheritedError triggers a reconnect,
41-
# so we need to disable reconnects to force
42-
# the exception bubble up
43-
redis.without_reconnect do
44-
redis.set "foo", 2
45-
end
46-
exit! 0
47-
rescue Redis::InheritedError
48-
exit! 127
34+
def test_fork_safety_with_enabled_inherited_socket
35+
redis = Redis.new(OPTIONS.merge(inherit_socket: true))
36+
redis.set "foo", 1
37+
38+
child_pid = fork do
39+
# InheritedError triggers a reconnect,
40+
# so we need to disable reconnects to force
41+
# the exception bubble up
42+
redis.without_reconnect do
43+
redis.set "foo", 2
4944
end
45+
exit! 0
46+
rescue Redis::InheritedError
47+
exit! 127
48+
end
5049

51-
_, status = Process.wait2(child_pid)
50+
_, status = Process.wait2(child_pid)
5251

53-
assert_equal 0, status.exitstatus
54-
assert_equal "2", redis.get("foo")
55-
end
52+
assert_equal 0, status.exitstatus
53+
assert_equal "2", redis.get("foo")
5654
end
5755
end

test/redis/internals_test.rb

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,16 @@ def test_connecting_to_unix_domain_socket
214214
Redis.new(OPTIONS.merge(path: ENV.fetch("REDIS_SOCKET_PATH"))).ping
215215
end
216216

217-
driver(:ruby, :hiredis) do
218-
def test_bubble_timeout_without_retrying
219-
serv = TCPServer.new(6380)
217+
def test_bubble_timeout_without_retrying
218+
serv = TCPServer.new(6380)
220219

221-
redis = Redis.new(port: 6380, timeout: 0.1)
220+
redis = Redis.new(port: 6380, timeout: 0.1)
222221

223-
assert_raises(Redis::TimeoutError) do
224-
redis.ping
225-
end
226-
ensure
227-
serv&.close
222+
assert_raises(Redis::TimeoutError) do
223+
redis.ping
228224
end
225+
ensure
226+
serv&.close
229227
end
230228

231229
def test_client_options
@@ -282,19 +280,15 @@ def af_test(host)
282280
redis_mock(commands, host: host, &:ping)
283281
end
284282

285-
driver(:ruby) do
286-
af_family_supported(Socket::AF_INET) do
287-
def test_connect_ipv4
288-
af_test("127.0.0.1")
289-
end
283+
af_family_supported(Socket::AF_INET) do
284+
def test_connect_ipv4
285+
af_test("127.0.0.1")
290286
end
291287
end
292288

293-
driver(:ruby) do
294-
af_family_supported(Socket::AF_INET6) do
295-
def test_connect_ipv6
296-
af_test("::1")
297-
end
289+
af_family_supported(Socket::AF_INET6) do
290+
def test_connect_ipv6
291+
af_test("::1")
298292
end
299293
end
300294

test/redis/thread_safety_test.rb

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,25 @@
55
class TestThreadSafety < Minitest::Test
66
include Helper::Client
77

8-
driver(:ruby, :hiredis) do
9-
def test_thread_safety
10-
redis = Redis.new(OPTIONS)
11-
redis.set "foo", 1
12-
redis.set "bar", 2
8+
def test_thread_safety
9+
redis = Redis.new(OPTIONS)
10+
redis.set "foo", 1
11+
redis.set "bar", 2
1312

14-
sample = 100
13+
sample = 100
1514

16-
t1 = Thread.new do
17-
@foos = Array.new(sample) { redis.get "foo" }
18-
end
15+
t1 = Thread.new do
16+
@foos = Array.new(sample) { redis.get "foo" }
17+
end
1918

20-
t2 = Thread.new do
21-
@bars = Array.new(sample) { redis.get "bar" }
22-
end
19+
t2 = Thread.new do
20+
@bars = Array.new(sample) { redis.get "bar" }
21+
end
2322

24-
t1.join
25-
t2.join
23+
t1.join
24+
t2.join
2625

27-
assert_equal ["1"], @foos.uniq
28-
assert_equal ["2"], @bars.uniq
29-
end
26+
assert_equal ["1"], @foos.uniq
27+
assert_equal ["2"], @bars.uniq
3028
end
3129
end

0 commit comments

Comments
 (0)