Skip to content

Commit b3df083

Browse files
committed
Skip RedisCacheStore test if no Redis server is running
MemCacheStore tests have been doing the same for a while. As an extra safety, if `ENV["CI"]` is set, we always run the tests.
1 parent 08358e0 commit b3df083

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

activesupport/test/cache/stores/mem_cache_store_test.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,19 @@ def alive?
2525
end
2626
end
2727

28-
begin
29-
servers = ENV["MEMCACHE_SERVERS"] || "localhost:11211"
30-
ss = Dalli::Client.new(servers).stats
31-
raise Dalli::DalliError unless ss[servers] || ss[servers + ":11211"]
32-
28+
if ENV["CI"]
3329
MEMCACHE_UP = true
34-
rescue Dalli::DalliError
35-
$stderr.puts "Skipping memcached tests. Start memcached and try again."
36-
MEMCACHE_UP = false
30+
else
31+
begin
32+
servers = ENV["MEMCACHE_SERVERS"] || "localhost:11211"
33+
ss = Dalli::Client.new(servers).stats
34+
raise Dalli::DalliError unless ss[servers] || ss[servers + ":11211"]
35+
36+
MEMCACHE_UP = true
37+
rescue Dalli::DalliError
38+
$stderr.puts "Skipping memcached tests. Start memcached and try again."
39+
MEMCACHE_UP = false
40+
end
3741
end
3842

3943
def lookup_store(options = {})

activesupport/test/cache/stores/redis_cache_store_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ def get(key)
2525
end
2626

2727
module ActiveSupport::Cache::RedisCacheStoreTests
28+
if ENV["CI"]
29+
REDIS_UP = true
30+
else
31+
begin
32+
redis = Redis.new(url: "redis://localhost:6379/0")
33+
redis.ping
34+
35+
REDIS_UP = true
36+
rescue Redis::BaseConnectionError
37+
$stderr.puts "Skipping redis tests. Start redis and try again."
38+
REDIS_UP = false
39+
end
40+
end
41+
2842
DRIVER = %w[ ruby hiredis ].include?(ENV["REDIS_DRIVER"]) ? ENV["REDIS_DRIVER"] : "hiredis"
2943

3044
class LookupTest < ActiveSupport::TestCase
@@ -110,6 +124,7 @@ def build(**kwargs)
110124

111125
class StoreTest < ActiveSupport::TestCase
112126
setup do
127+
skip "redis server is not up" unless REDIS_UP
113128
@namespace = "test-#{SecureRandom.hex}"
114129

115130
@cache = lookup_store(expires_in: 60)

0 commit comments

Comments
 (0)