From 72d14a11ab7c47f993dbaa7f62c646acbe2c0056 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Thu, 21 Feb 2019 15:03:55 +0800 Subject: [PATCH] DEV: Properly flush `DistributedMemoizer` in spec. - $redis.flushall may hide state leak from other tests. --- lib/distributed_memoizer.rb | 5 +++++ spec/requests/static_controller_spec.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/distributed_memoizer.rb b/lib/distributed_memoizer.rb index e80b687923a..3be926658a5 100644 --- a/lib/distributed_memoizer.rb +++ b/lib/distributed_memoizer.rb @@ -46,6 +46,11 @@ class DistributedMemoizer "memoize_" << key end + # Used for testing + def self.flush! + $redis.scan_each(match: "memoize_*").each { |key| $redis.del(key) } + end + protected def self.get_lock(redis, redis_lock_key) diff --git a/spec/requests/static_controller_spec.rb b/spec/requests/static_controller_spec.rb index b3613bea94f..7db1cdbb21b 100644 --- a/spec/requests/static_controller_spec.rb +++ b/spec/requests/static_controller_spec.rb @@ -9,7 +9,7 @@ describe StaticController do before { FinalDestination.stubs(:lookup_ip).returns("1.2.3.4") } after do - $redis.flushall + DistributedMemoizer.flush! end it 'returns the default favicon for a missing download' do