From c1501e04d00c400a9090f54b558b3e376eab4656 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Tue, 13 Apr 2021 18:07:12 +0200 Subject: [PATCH] Add a test case for race_condition_ttl with local_cache enabled --- .../test/cache/behaviors/local_cache_behavior.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/activesupport/test/cache/behaviors/local_cache_behavior.rb b/activesupport/test/cache/behaviors/local_cache_behavior.rb index f45230afb8..125741de3d 100644 --- a/activesupport/test/cache/behaviors/local_cache_behavior.rb +++ b/activesupport/test/cache/behaviors/local_cache_behavior.rb @@ -214,4 +214,18 @@ module LocalCacheBehavior app = @cache.middleware.new(app) app.call({}) end + + def test_local_race_condition_protection + @cache.with_local_cache do + time = Time.now + @cache.write("foo", "bar", expires_in: 60) + Time.stub(:now, time + 61) do + result = @cache.fetch("foo", race_condition_ttl: 10) do + assert_equal "bar", @cache.read("foo") + "baz" + end + assert_equal "baz", result + end + end + end end