aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/cache/stores/mem_cache_store_test.rb
diff options
context:
space:
mode:
authorfatkodima <fatkodima@rambler.ru>2017-12-16 22:33:22 +0200
committerfatkodima <fatkodima123@gmail.com>2018-01-23 00:34:21 +0200
commitbd54991d20aa30a76815ce80912c8122a2e4ffd3 (patch)
tree3920d4c9e0e6986911fd6433ddc1006132258757 /activesupport/test/cache/stores/mem_cache_store_test.rb
parent05b7b80bcaeeb0357cdb6143fbeca1b3c73b5fb9 (diff)
downloadrails-bd54991d20aa30a76815ce80912c8122a2e4ffd3.tar.gz
rails-bd54991d20aa30a76815ce80912c8122a2e4ffd3.tar.bz2
rails-bd54991d20aa30a76815ce80912c8122a2e4ffd3.zip
Improve fault tolerance for redis cache store
Diffstat (limited to 'activesupport/test/cache/stores/mem_cache_store_test.rb')
-rw-r--r--activesupport/test/cache/stores/mem_cache_store_test.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/activesupport/test/cache/stores/mem_cache_store_test.rb b/activesupport/test/cache/stores/mem_cache_store_test.rb
index ccb3b7403f..3e2316f217 100644
--- a/activesupport/test/cache/stores/mem_cache_store_test.rb
+++ b/activesupport/test/cache/stores/mem_cache_store_test.rb
@@ -17,6 +17,12 @@ class SlowDalliClient < Dalli::Client
end
end
+class UnavailableDalliServer < Dalli::Server
+ def alive?
+ false
+ end
+end
+
class MemCacheStoreTest < ActiveSupport::TestCase
begin
ss = Dalli::Client.new("localhost:11211").stats
@@ -46,6 +52,7 @@ class MemCacheStoreTest < ActiveSupport::TestCase
include EncodedKeyCacheBehavior
include AutoloadingCacheBehavior
include ConnectionPoolBehavior
+ include FailureSafetyBehavior
def test_raw_values
cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, raw: true)
@@ -118,4 +125,14 @@ class MemCacheStoreTest < ActiveSupport::TestCase
Dalli.send(:remove_const, :Client)
Dalli.const_set(:Client, old_client)
end
+
+ def emulating_unavailability
+ old_server = Dalli.send(:remove_const, :Server)
+ Dalli.const_set(:Server, UnavailableDalliServer)
+
+ yield ActiveSupport::Cache::MemCacheStore.new
+ ensure
+ Dalli.send(:remove_const, :Server)
+ Dalli.const_set(:Server, old_server)
+ end
end