mirror of https://github.com/rails/rails
Stop testing hiredis
The driver being used is an implementation detail of `redis-rb`. If somehow something break on one driver but not the other, it should be reported to redis-rb and fixed there. Also `redis-rb` `5.0` has a totally new client and hiredis binding so all this code no longer works with redis-rb 5.0.
This commit is contained in:
parent
d1a9a9928d
commit
f2ab66da73
3
Gemfile
3
Gemfile
|
@ -85,8 +85,7 @@ end
|
||||||
group :cable do
|
group :cable do
|
||||||
gem "puma", require: false
|
gem "puma", require: false
|
||||||
|
|
||||||
gem "hiredis", require: false
|
gem "redis", ">= 4.0.1", require: false
|
||||||
gem "redis", "~> 4.0", require: false
|
|
||||||
|
|
||||||
gem "redis-namespace"
|
gem "redis-namespace"
|
||||||
|
|
||||||
|
|
|
@ -284,7 +284,6 @@ GEM
|
||||||
os (>= 0.9, < 2.0)
|
os (>= 0.9, < 2.0)
|
||||||
signet (>= 0.16, < 2.a)
|
signet (>= 0.16, < 2.a)
|
||||||
hashdiff (1.0.1)
|
hashdiff (1.0.1)
|
||||||
hiredis (0.6.3)
|
|
||||||
http_parser.rb (0.8.0)
|
http_parser.rb (0.8.0)
|
||||||
httpclient (2.8.3)
|
httpclient (2.8.3)
|
||||||
i18n (1.8.11)
|
i18n (1.8.11)
|
||||||
|
@ -400,7 +399,7 @@ GEM
|
||||||
rbtree (0.4.5)
|
rbtree (0.4.5)
|
||||||
rdoc (6.3.3)
|
rdoc (6.3.3)
|
||||||
redcarpet (3.2.3)
|
redcarpet (3.2.3)
|
||||||
redis (4.5.1)
|
redis (4.7.1)
|
||||||
redis-namespace (1.8.1)
|
redis-namespace (1.8.1)
|
||||||
redis (>= 3.0.4)
|
redis (>= 3.0.4)
|
||||||
regexp_parser (2.2.1)
|
regexp_parser (2.2.1)
|
||||||
|
@ -574,7 +573,6 @@ DEPENDENCIES
|
||||||
delayed_job
|
delayed_job
|
||||||
delayed_job_active_record
|
delayed_job_active_record
|
||||||
google-cloud-storage (~> 1.11)
|
google-cloud-storage (~> 1.11)
|
||||||
hiredis
|
|
||||||
image_processing (~> 1.2)
|
image_processing (~> 1.2)
|
||||||
importmap-rails
|
importmap-rails
|
||||||
jsbundling-rails
|
jsbundling-rails
|
||||||
|
@ -598,7 +596,7 @@ DEPENDENCIES
|
||||||
rails!
|
rails!
|
||||||
rake (>= 11.1)
|
rake (>= 11.1)
|
||||||
redcarpet (~> 3.2.3)
|
redcarpet (~> 3.2.3)
|
||||||
redis (~> 4.0)
|
redis (>= 4.0.1)
|
||||||
redis-namespace
|
redis-namespace
|
||||||
resque
|
resque
|
||||||
resque-scheduler
|
resque-scheduler
|
||||||
|
|
|
@ -17,12 +17,6 @@ class RedisAdapterTest < ActionCable::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class RedisAdapterTest::Hiredis < RedisAdapterTest
|
|
||||||
def cable_config
|
|
||||||
super.merge(driver: "hiredis")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class RedisAdapterTest::AlternateConfiguration < RedisAdapterTest
|
class RedisAdapterTest::AlternateConfiguration < RedisAdapterTest
|
||||||
def cable_config
|
def cable_config
|
||||||
alt_cable_config = super.dup
|
alt_cable_config = super.dup
|
||||||
|
|
|
@ -13,29 +13,10 @@ Rake::TestTask.new do |t|
|
||||||
t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION)
|
t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION)
|
||||||
end
|
end
|
||||||
|
|
||||||
Rake::Task[:test].enhance do
|
|
||||||
Rake::Task["test:cache_stores:redis:ruby"].invoke
|
|
||||||
end
|
|
||||||
|
|
||||||
namespace :test do
|
namespace :test do
|
||||||
task :isolated do
|
task :isolated do
|
||||||
Dir.glob("test/**/*_test.rb").all? do |file|
|
Dir.glob("test/**/*_test.rb").all? do |file|
|
||||||
sh(Gem.ruby, "-w", file)
|
sh(Gem.ruby, "-w", file)
|
||||||
end || raise("Failures")
|
end || raise("Failures")
|
||||||
end
|
end
|
||||||
|
|
||||||
namespace :cache_stores do
|
|
||||||
namespace :redis do
|
|
||||||
%w[ ruby hiredis ].each do |driver|
|
|
||||||
task("env:#{driver}") { ENV["REDIS_DRIVER"] = driver }
|
|
||||||
|
|
||||||
Rake::TestTask.new(driver => "env:#{driver}") do |t|
|
|
||||||
t.test_files = ["test/cache/stores/redis_cache_store_test.rb"]
|
|
||||||
t.warning = true
|
|
||||||
t.verbose = true
|
|
||||||
t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,16 +5,10 @@ begin
|
||||||
require "redis"
|
require "redis"
|
||||||
require "redis/distributed"
|
require "redis/distributed"
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
warn "The Redis cache store requires the redis gem, version 4.0.1 or later. Please add it to your Gemfile: `gem \"redis\", \"~> 4.0\"`"
|
warn "The Redis cache store requires the redis gem, version 4.0.1 or later. Please add it to your Gemfile: `gem \"redis\", \">= 4.0.1\"`"
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
|
|
||||||
# Prefer the hiredis driver but don't require it.
|
|
||||||
begin
|
|
||||||
require "redis/connection/hiredis"
|
|
||||||
rescue LoadError
|
|
||||||
end
|
|
||||||
|
|
||||||
require "connection_pool"
|
require "connection_pool"
|
||||||
require "active_support/core_ext/numeric/time"
|
require "active_support/core_ext/numeric/time"
|
||||||
require "active_support/digest"
|
require "active_support/digest"
|
||||||
|
|
|
@ -5,12 +5,6 @@ require "active_support/cache"
|
||||||
require "active_support/cache/redis_cache_store"
|
require "active_support/cache/redis_cache_store"
|
||||||
require_relative "../behaviors"
|
require_relative "../behaviors"
|
||||||
|
|
||||||
driver_name = %w[ ruby hiredis ].include?(ENV["REDIS_DRIVER"]) ? ENV["REDIS_DRIVER"] : "hiredis"
|
|
||||||
driver = Object.const_get("Redis::Connection::#{driver_name.camelize}")
|
|
||||||
|
|
||||||
Redis::Connection.drivers.clear
|
|
||||||
Redis::Connection.drivers.append(driver)
|
|
||||||
|
|
||||||
# Emulates a latency on Redis's back-end for the key latency to facilitate
|
# Emulates a latency on Redis's back-end for the key latency to facilitate
|
||||||
# connection pool testing.
|
# connection pool testing.
|
||||||
class SlowRedis < Redis
|
class SlowRedis < Redis
|
||||||
|
@ -42,8 +36,6 @@ module ActiveSupport::Cache::RedisCacheStoreTests
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
DRIVER = %w[ ruby hiredis ].include?(ENV["REDIS_DRIVER"]) ? ENV["REDIS_DRIVER"] : "hiredis"
|
|
||||||
|
|
||||||
class LookupTest < ActiveSupport::TestCase
|
class LookupTest < ActiveSupport::TestCase
|
||||||
test "may be looked up as :redis_cache_store" do
|
test "may be looked up as :redis_cache_store" do
|
||||||
assert_kind_of ActiveSupport::Cache::RedisCacheStore,
|
assert_kind_of ActiveSupport::Cache::RedisCacheStore,
|
||||||
|
@ -56,7 +48,7 @@ module ActiveSupport::Cache::RedisCacheStoreTests
|
||||||
assert_called_with Redis, :new, [
|
assert_called_with Redis, :new, [
|
||||||
url: nil,
|
url: nil,
|
||||||
connect_timeout: 20, read_timeout: 1, write_timeout: 1,
|
connect_timeout: 20, read_timeout: 1, write_timeout: 1,
|
||||||
reconnect_attempts: 0, driver: DRIVER
|
reconnect_attempts: 0
|
||||||
] do
|
] do
|
||||||
build
|
build
|
||||||
end
|
end
|
||||||
|
@ -66,7 +58,7 @@ module ActiveSupport::Cache::RedisCacheStoreTests
|
||||||
assert_called_with Redis, :new, [
|
assert_called_with Redis, :new, [
|
||||||
url: nil,
|
url: nil,
|
||||||
connect_timeout: 20, read_timeout: 1, write_timeout: 1,
|
connect_timeout: 20, read_timeout: 1, write_timeout: 1,
|
||||||
reconnect_attempts: 0, driver: DRIVER
|
reconnect_attempts: 0
|
||||||
] do
|
] do
|
||||||
build url: []
|
build url: []
|
||||||
end
|
end
|
||||||
|
@ -76,7 +68,7 @@ module ActiveSupport::Cache::RedisCacheStoreTests
|
||||||
assert_called_with Redis, :new, [
|
assert_called_with Redis, :new, [
|
||||||
url: REDIS_URL,
|
url: REDIS_URL,
|
||||||
connect_timeout: 20, read_timeout: 1, write_timeout: 1,
|
connect_timeout: 20, read_timeout: 1, write_timeout: 1,
|
||||||
reconnect_attempts: 0, driver: DRIVER
|
reconnect_attempts: 0
|
||||||
] do
|
] do
|
||||||
build url: REDIS_URL
|
build url: REDIS_URL
|
||||||
end
|
end
|
||||||
|
@ -86,7 +78,7 @@ module ActiveSupport::Cache::RedisCacheStoreTests
|
||||||
assert_called_with Redis, :new, [
|
assert_called_with Redis, :new, [
|
||||||
url: REDIS_URL,
|
url: REDIS_URL,
|
||||||
connect_timeout: 20, read_timeout: 1, write_timeout: 1,
|
connect_timeout: 20, read_timeout: 1, write_timeout: 1,
|
||||||
reconnect_attempts: 0, driver: DRIVER
|
reconnect_attempts: 0
|
||||||
] do
|
] do
|
||||||
build url: [ REDIS_URL ]
|
build url: [ REDIS_URL ]
|
||||||
end
|
end
|
||||||
|
@ -98,7 +90,6 @@ module ActiveSupport::Cache::RedisCacheStoreTests
|
||||||
read_timeout: 1,
|
read_timeout: 1,
|
||||||
write_timeout: 1,
|
write_timeout: 1,
|
||||||
reconnect_attempts: 0,
|
reconnect_attempts: 0,
|
||||||
driver: DRIVER
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mock = Minitest::Mock.new
|
mock = Minitest::Mock.new
|
||||||
|
@ -128,7 +119,7 @@ module ActiveSupport::Cache::RedisCacheStoreTests
|
||||||
|
|
||||||
private
|
private
|
||||||
def build(**kwargs)
|
def build(**kwargs)
|
||||||
ActiveSupport::Cache::RedisCacheStore.new(driver: DRIVER, **kwargs.merge(pool: false)).tap(&:redis)
|
ActiveSupport::Cache::RedisCacheStore.new(**kwargs.merge(pool: false)).tap(&:redis)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -146,7 +137,7 @@ module ActiveSupport::Cache::RedisCacheStoreTests
|
||||||
end
|
end
|
||||||
|
|
||||||
def lookup_store(options = {})
|
def lookup_store(options = {})
|
||||||
ActiveSupport::Cache.lookup_store(:redis_cache_store, { timeout: 0.1, namespace: @namespace, driver: DRIVER, pool: false }.merge(options))
|
ActiveSupport::Cache.lookup_store(:redis_cache_store, { timeout: 0.1, namespace: @namespace, pool: false }.merge(options))
|
||||||
end
|
end
|
||||||
|
|
||||||
teardown do
|
teardown do
|
||||||
|
@ -452,7 +443,7 @@ module ActiveSupport::Cache::RedisCacheStoreTests
|
||||||
test "clear all cache key with Redis::Distributed" do
|
test "clear all cache key with Redis::Distributed" do
|
||||||
cache = ActiveSupport::Cache::RedisCacheStore.new(
|
cache = ActiveSupport::Cache::RedisCacheStore.new(
|
||||||
url: REDIS_URLS,
|
url: REDIS_URLS,
|
||||||
timeout: 0.1, namespace: @namespace, expires_in: 60, driver: DRIVER)
|
timeout: 0.1, namespace: @namespace, expires_in: 60)
|
||||||
cache.write("foo", "bar")
|
cache.write("foo", "bar")
|
||||||
cache.write("fu", "baz")
|
cache.write("fu", "baz")
|
||||||
cache.clear
|
cache.clear
|
||||||
|
|
|
@ -517,16 +517,6 @@ To get started, add the redis gem to your Gemfile:
|
||||||
gem 'redis'
|
gem 'redis'
|
||||||
```
|
```
|
||||||
|
|
||||||
You can enable support for the faster [hiredis](https://github.com/redis/hiredis)
|
|
||||||
connection library by additionally adding its ruby wrapper to your Gemfile:
|
|
||||||
|
|
||||||
```ruby
|
|
||||||
gem 'hiredis'
|
|
||||||
```
|
|
||||||
|
|
||||||
Redis cache store will automatically require and use hiredis if available. No further
|
|
||||||
configuration is needed.
|
|
||||||
|
|
||||||
Finally, add the configuration in the relevant `config/environments/*.rb` file:
|
Finally, add the configuration in the relevant `config/environments/*.rb` file:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
|
|
Loading…
Reference in New Issue