Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/solid_cache/store/failsafe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Store
module Failsafe
TRANSIENT_ACTIVE_RECORD_ERRORS = [
ActiveRecord::AdapterTimeout,
ActiveRecord::ConnectionFailed,
ActiveRecord::ConnectionNotEstablished,
ActiveRecord::Deadlocked,
ActiveRecord::LockWaitTimeout,
Expand Down
4 changes: 2 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ def shard_keys(cache, shard)
shard_keys.map { |key| key.delete_prefix("#{@namespace}:") }
end

def emulating_timeouts
def emulating_timeouts(error = ActiveRecord::StatementTimeout)
ar_methods = [ :select_all, :delete, :exec_insert_all ]
stub_matcher = ActiveRecord::Base.connection.class.any_instance
ar_methods.each { |method| stub_matcher.stubs(method).raises(ActiveRecord::StatementTimeout) }
ar_methods.each { |method| stub_matcher.stubs(method).raises(error) }
yield
ensure
ar_methods.each { |method| stub_matcher.unstub(method) }
Expand Down
21 changes: 21 additions & 0 deletions test/unit/solid_cache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,27 @@ def emulating_unavailability
end
end

class SolidCacheFailsafeConnectionFailedTest < ActiveSupport::TestCase
include FailureSafetyBehavior

setup do
@cache = nil
@namespace = "test-#{SecureRandom.hex}"

@cache = lookup_store(expires_in: 60)

# For LocalCacheBehavior tests
@peek = lookup_store(expires_in: 60)
end

def emulating_unavailability
wait_for_background_tasks(@cache)
emulating_timeouts(ActiveRecord::ConnectionFailed) do
yield lookup_store(namespace: @namespace)
end
end
end

class SolidCacheRaisingTest < ActiveSupport::TestCase
include FailureRaisingBehavior

Expand Down
Loading