Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31487 from fatkodima/improve_cache_fault_tolerance
Improve fault tolerance for redis cache store
- Loading branch information
Showing
5 changed files
with
137 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
activesupport/test/cache/behaviors/failure_safety_behavior.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# frozen_string_literal: true | ||
|
||
module FailureSafetyBehavior | ||
def test_fetch_read_failure_returns_nil | ||
@cache.write("foo", "bar") | ||
|
||
emulating_unavailability do |cache| | ||
assert_nil cache.fetch("foo") | ||
end | ||
end | ||
|
||
def test_fetch_read_failure_does_not_attempt_to_write | ||
end | ||
|
||
def test_read_failure_returns_nil | ||
@cache.write("foo", "bar") | ||
|
||
emulating_unavailability do |cache| | ||
assert_nil cache.read("foo") | ||
end | ||
end | ||
|
||
def test_read_multi_failure_returns_empty_hash | ||
@cache.write_multi("foo" => "bar", "baz" => "quux") | ||
|
||
emulating_unavailability do |cache| | ||
assert_equal Hash.new, cache.read_multi("foo", "baz") | ||
end | ||
end | ||
|
||
def test_write_failure_returns_false | ||
emulating_unavailability do |cache| | ||
assert_equal false, cache.write("foo", "bar") | ||
end | ||
end | ||
|
||
def test_write_multi_failure_not_raises | ||
emulating_unavailability do |cache| | ||
assert_nothing_raised do | ||
cache.write_multi("foo" => "bar", "baz" => "quux") | ||
end | ||
end | ||
end | ||
|
||
def test_fetch_multi_failure_returns_fallback_results | ||
@cache.write_multi("foo" => "bar", "baz" => "quux") | ||
|
||
emulating_unavailability do |cache| | ||
fetched = cache.fetch_multi("foo", "baz") { |k| "unavailable" } | ||
assert_equal Hash["foo" => "unavailable", "baz" => "unavailable"], fetched | ||
end | ||
end | ||
|
||
def test_delete_failure_returns_false | ||
@cache.write("foo", "bar") | ||
|
||
emulating_unavailability do |cache| | ||
assert_equal false, cache.delete("foo") | ||
end | ||
end | ||
|
||
def test_exist_failure_returns_false | ||
@cache.write("foo", "bar") | ||
|
||
emulating_unavailability do |cache| | ||
assert !cache.exist?("foo") | ||
end | ||
end | ||
|
||
def test_increment_failure_returns_nil | ||
@cache.write("foo", 1, raw: true) | ||
|
||
emulating_unavailability do |cache| | ||
assert_nil cache.increment("foo") | ||
end | ||
end | ||
|
||
def test_decrement_failure_returns_nil | ||
@cache.write("foo", 1, raw: true) | ||
|
||
emulating_unavailability do |cache| | ||
assert_nil cache.decrement("foo") | ||
end | ||
end | ||
|
||
def test_clear_failure_returns_nil | ||
emulating_unavailability do |cache| | ||
assert_nil cache.clear | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters