Acceptance test plain redis as a cache store backend

This commit is contained in:
Gonzalo Rodriguez 2018-06-26 13:52:32 -03:00
parent 6fbb6c8b1c
commit e50bfbebaa
No known key found for this signature in database
GPG key ID: 5DB8B81B049B8AB1
4 changed files with 52 additions and 0 deletions

View file

@ -26,6 +26,7 @@ gemfile:
- gemfiles/rails_5_1.gemfile
- gemfiles/rails_4_2.gemfile
- gemfiles/dalli2.gemfile
- gemfiles/redis_4.gemfile
- gemfiles/connection_pool_dalli.gemfile
- gemfiles/active_support_redis_cache_store.gemfile
- gemfiles/active_support_redis_cache_store_pooled.gemfile

View file

@ -40,6 +40,10 @@ appraise 'dalli2' do
gem 'dalli', '~> 2.0'
end
appraise 'redis_4' do
gem 'redis', '~> 4.0'
end
appraise "connection_pool_dalli" do
gem "connection_pool", "~> 2.2"
gem "dalli", "~> 2.7"

7
gemfiles/redis_4.gemfile Normal file
View file

@ -0,0 +1,7 @@
# This file was generated by Appraisal
source "https://rubygems.org"
gem "redis", "~> 4.0"
gemspec path: "../"

View file

@ -0,0 +1,40 @@
require_relative "../../spec_helper"
if defined?(::Redis)
require_relative "../../support/cache_store_helper"
require "timecop"
describe "Plain redis as a cache backend" do
before do
Rack::Attack.cache.store = Redis.new
end
after do
Rack::Attack.cache.store.flushdb
end
it_works_for_cache_backed_features
it "doesn't leak keys" do
Rack::Attack.throttle("by ip", limit: 1, period: 1) do |request|
request.ip
end
key = nil
# Freeze time during these statement to be sure that the key used by rack attack is the same
# we pre-calculate in local variable `key`
Timecop.freeze do
key = "rack::attack:#{Time.now.to_i}:by ip:1.2.3.4"
get "/", {}, "REMOTE_ADDR" => "1.2.3.4"
end
assert Rack::Attack.cache.store.get(key)
sleep 2.1
assert_nil Rack::Attack.cache.store.get(key)
end
end
end