diff --git a/Appraisals b/Appraisals index 319a736c78..3355f23ba6 100644 --- a/Appraisals +++ b/Appraisals @@ -259,6 +259,7 @@ elsif ruby_version?('2.2') gem 'sprockets', '< 4' gem 'lograge', '~> 0.11' gem 'mimemagic', '0.3.9' # Pinned until https://github.com/mimemagicrb/mimemagic/issues/142 is resolved. + gem 'redis-rails' end appraise 'rails5-postgres-sidekiq' do @@ -454,6 +455,8 @@ elsif ruby_version?('2.3') gem 'redis', '>= 4.0.1' gem 'sprockets', '< 4' gem 'lograge', '~> 0.11' + gem 'redis-rails' + gem 'redis-store', '> 1.6.0' end appraise 'rails5-postgres-sidekiq' do @@ -570,6 +573,7 @@ elsif ruby_version?('2.4') gem 'redis', '>= 4.0.1' gem 'sprockets', '< 4' gem 'lograge', '~> 0.11' + gem 'redis-rails' end appraise 'rails5-postgres-sidekiq' do @@ -697,6 +701,7 @@ elsif ruby_version?('2.5') gem 'sprockets', '< 4' gem 'lograge', '~> 0.11' gem 'i18n', '1.8.7', platform: :jruby # Removal pending: https://github.com/ruby-i18n/i18n/issues/555#issuecomment-772112169 + gem 'redis-rails' end appraise 'rails5-postgres-sidekiq' do @@ -755,6 +760,7 @@ elsif ruby_version?('2.5') gem 'sprockets', '< 4' gem 'lograge', '~> 0.11' gem 'i18n', '1.8.7', platform: :jruby # Removal pending: https://github.com/ruby-i18n/i18n/issues/555#issuecomment-772112169 + gem 'redis-rails' end appraise 'rails6-postgres-sidekiq' do @@ -925,6 +931,7 @@ elsif ruby_version?('2.6') gem 'redis', '>= 4.0.1' gem 'sprockets', '< 4' gem 'lograge', '~> 0.11' + gem 'redis-rails' end appraise 'rails5-postgres-sidekiq' do @@ -971,6 +978,7 @@ elsif ruby_version?('2.6') gem 'redis', '>= 4.0.1' gem 'sprockets', '< 4' gem 'lograge', '~> 0.11' + gem 'redis-rails' end appraise 'rails6-postgres-sidekiq' do @@ -1115,7 +1123,6 @@ elsif ruby_version?('2.7') appraise 'rails5-postgres-redis' do gem 'rails', '~> 5.2.1' gem 'pg', '< 1.0', platform: :ruby - gem 'redis-rails' gem 'redis' gem 'sprockets', '< 4' gem 'lograge', '~> 0.11' @@ -1124,10 +1131,10 @@ elsif ruby_version?('2.7') appraise 'rails5-postgres-redis-activesupport' do gem 'rails', '~> 5.2.1' gem 'pg', '< 1.0', platform: :ruby - gem 'redis-rails' gem 'redis' gem 'sprockets', '< 4' gem 'lograge', '~> 0.11' + gem 'redis-rails' end appraise 'rails5-postgres-sidekiq' do @@ -1163,7 +1170,6 @@ elsif ruby_version?('2.7') appraise 'rails6-postgres-redis' do gem 'rails', '~> 6.0.0' gem 'pg', '< 1.0', platform: :ruby - gem 'redis-rails' gem 'redis' gem 'sprockets', '< 4' gem 'lograge', '~> 0.11' @@ -1172,10 +1178,10 @@ elsif ruby_version?('2.7') appraise 'rails6-postgres-redis-activesupport' do gem 'rails', '~> 6.0.0' gem 'pg', '< 1.0', platform: :ruby - gem 'redis-rails' gem 'redis' gem 'sprockets', '< 4' gem 'lograge', '~> 0.11' + gem 'redis-rails' end appraise 'rails6-postgres-sidekiq' do diff --git a/Rakefile b/Rakefile index 5adbdebfcf..0c181e95b6 100644 --- a/Rakefile +++ b/Rakefile @@ -13,7 +13,7 @@ desc 'Run RSpec' # rubocop:disable Metrics/BlockLength namespace :spec do task all: [:main, :benchmark, - :rails, :railsredis, :railsactivejob, + :rails, :railsredis, :railsredis_activesupport, :railsactivejob, :elasticsearch, :http, :redis, :sidekiq, :sinatra] RSpec::Core::RakeTask.new(:main) do |t, args| @@ -51,6 +51,14 @@ namespace :spec do t.rspec_opts = args.to_a.join(' ') end + RSpec::Core::RakeTask.new(:railsredis_activesupport) do |t, args| + t.pattern = 'spec/ddtrace/contrib/rails/**/*redis*_spec.rb' + t.rspec_opts = args.to_a.join(' ') + + # Flag used to tell specs the expected configuration (so that they break if they're not being setup correctly) + ENV['EXPECT_RAILS_ACTIVESUPPORT'] = 'true' + end + RSpec::Core::RakeTask.new(:railsactivejob) do |t, args| t.pattern = 'spec/ddtrace/contrib/rails/**/*active_job*_spec.rb' t.rspec_opts = args.to_a.join(' ') @@ -273,12 +281,12 @@ task :ci do declare 'bundle exec appraisal rails30-postgres rake spec:railsautoinstrument' declare 'bundle exec appraisal rails32-mysql2 rake test:rails' declare 'bundle exec appraisal rails32-postgres rake test:rails' - declare 'bundle exec appraisal rails32-postgres-redis rake spec:railsredis' + declare 'bundle exec appraisal rails32-postgres-redis rake spec:railsredis_activesupport' declare 'bundle exec appraisal rails32-postgres rake spec:railsdisableenv' declare 'bundle exec appraisal rails32-postgres rake spec:railsautoinstrument' declare 'bundle exec appraisal rails4-mysql2 rake test:rails' declare 'bundle exec appraisal rails4-postgres rake test:rails' - declare 'bundle exec appraisal rails4-postgres-redis rake spec:railsredis' + declare 'bundle exec appraisal rails4-postgres-redis rake spec:railsredis_activesupport' declare 'bundle exec appraisal rails4-postgres rake spec:railsdisableenv' declare 'bundle exec appraisal rails4-postgres rake spec:railsautoinstrument' declare 'bundle exec appraisal rails4-semantic-logger rake spec:railssemanticlogger' @@ -352,19 +360,19 @@ task :ci do declare 'bundle exec appraisal rails30-postgres rake spec:railsautoinstrument' declare 'bundle exec appraisal rails32-mysql2 rake test:rails' declare 'bundle exec appraisal rails32-postgres rake test:rails' - declare 'bundle exec appraisal rails32-postgres-redis rake spec:railsredis' + declare 'bundle exec appraisal rails32-postgres-redis rake spec:railsredis_activesupport' declare 'bundle exec appraisal rails32-postgres rake spec:railsdisableenv' declare 'bundle exec appraisal rails32-postgres rake spec:railsautoinstrument' declare 'bundle exec appraisal rails4-mysql2 rake test:rails' declare 'bundle exec appraisal rails4-postgres rake test:rails' - declare 'bundle exec appraisal rails4-postgres-redis rake spec:railsredis' + declare 'bundle exec appraisal rails4-postgres-redis rake spec:railsredis_activesupport' declare 'bundle exec appraisal rails4-postgres rake spec:railsdisableenv' declare 'bundle exec appraisal rails4-postgres rake spec:railsautoinstrument' declare 'bundle exec appraisal rails4-postgres-sidekiq rake spec:railsactivejob' declare 'bundle exec appraisal rails5-mysql2 rake test:rails' declare 'bundle exec appraisal rails5-postgres rake test:rails' declare 'bundle exec appraisal rails5-postgres-redis rake spec:railsredis' - declare 'bundle exec appraisal rails5-postgres-redis-activesupport rake spec:railsredis' + declare 'bundle exec appraisal rails5-postgres-redis-activesupport rake spec:railsredis_activesupport' declare 'bundle exec appraisal rails5-postgres-sidekiq rake spec:railsactivejob' declare 'bundle exec appraisal rails5-postgres rake spec:railsdisableenv' declare 'bundle exec appraisal rails5-postgres rake spec:railsautoinstrument' @@ -438,19 +446,19 @@ task :ci do declare 'bundle exec appraisal rails30-postgres rake spec:railsautoinstrument' declare 'bundle exec appraisal rails32-mysql2 rake test:rails' declare 'bundle exec appraisal rails32-postgres rake test:rails' - declare 'bundle exec appraisal rails32-postgres-redis rake spec:railsredis' + declare 'bundle exec appraisal rails32-postgres-redis rake spec:railsredis_activesupport' declare 'bundle exec appraisal rails32-postgres rake spec:railsdisableenv' declare 'bundle exec appraisal rails32-postgres rake spec:railsautoinstrument' declare 'bundle exec appraisal rails4-mysql2 rake test:rails' declare 'bundle exec appraisal rails4-postgres rake test:rails' - declare 'bundle exec appraisal rails4-postgres-redis rake spec:railsredis' + declare 'bundle exec appraisal rails4-postgres-redis rake spec:railsredis_activesupport' declare 'bundle exec appraisal rails4-postgres rake spec:railsdisableenv' declare 'bundle exec appraisal rails4-postgres rake spec:railsautoinstrument' declare 'bundle exec appraisal rails4-postgres-sidekiq rake spec:railsactivejob' declare 'bundle exec appraisal rails5-mysql2 rake test:rails' declare 'bundle exec appraisal rails5-postgres rake test:rails' declare 'bundle exec appraisal rails5-postgres-redis rake spec:railsredis' - declare 'bundle exec appraisal rails5-postgres-redis-activesupport rake spec:railsredis' + declare 'bundle exec appraisal rails5-postgres-redis-activesupport rake spec:railsredis_activesupport' declare 'bundle exec appraisal rails5-postgres-sidekiq rake spec:railsactivejob' declare 'bundle exec appraisal rails5-postgres rake spec:railsdisableenv' declare 'bundle exec appraisal rails5-postgres rake spec:railsautoinstrument' @@ -528,7 +536,7 @@ task :ci do declare 'bundle exec appraisal rails5-mysql2 rake test:rails' declare 'bundle exec appraisal rails5-postgres rake test:rails' declare 'bundle exec appraisal rails5-postgres-redis rake spec:railsredis' - declare 'bundle exec appraisal rails5-postgres-redis-activesupport rake spec:railsredis' + declare 'bundle exec appraisal rails5-postgres-redis-activesupport rake spec:railsredis_activesupport' declare 'bundle exec appraisal rails5-postgres-sidekiq rake spec:railsactivejob' declare 'bundle exec appraisal rails5-postgres rake spec:railsdisableenv' declare 'bundle exec appraisal rails5-postgres rake spec:railsautoinstrument' @@ -605,14 +613,14 @@ task :ci do declare 'bundle exec appraisal rails5-mysql2 rake test:rails' declare 'bundle exec appraisal rails5-postgres rake test:rails' declare 'bundle exec appraisal rails5-postgres-redis rake spec:railsredis' - declare 'bundle exec appraisal rails5-postgres-redis-activesupport rake spec:railsredis' + declare 'bundle exec appraisal rails5-postgres-redis-activesupport rake spec:railsredis_activesupport' declare 'bundle exec appraisal rails5-postgres-sidekiq rake spec:railsactivejob' declare 'bundle exec appraisal rails5-postgres rake spec:railsdisableenv' declare 'bundle exec appraisal rails5-postgres rake spec:railsautoinstrument' declare 'bundle exec appraisal rails6-mysql2 rake test:rails' declare 'bundle exec appraisal rails6-postgres rake test:rails' declare 'bundle exec appraisal rails6-postgres-redis rake spec:railsredis' - declare 'bundle exec appraisal rails6-postgres-redis-activesupport rake spec:railsredis' + declare 'bundle exec appraisal rails6-postgres-redis-activesupport rake spec:railsredis_activesupport' declare 'bundle exec appraisal rails6-postgres-sidekiq rake spec:railsactivejob' declare 'bundle exec appraisal rails6-postgres rake spec:railsdisableenv' declare 'bundle exec appraisal rails6-postgres rake spec:railsautoinstrument' @@ -707,14 +715,14 @@ task :ci do declare 'bundle exec appraisal rails5-mysql2 rake test:rails' declare 'bundle exec appraisal rails5-postgres rake test:rails' declare 'bundle exec appraisal rails5-postgres-redis rake spec:railsredis' - declare 'bundle exec appraisal rails5-postgres-redis-activesupport rake spec:railsredis' + declare 'bundle exec appraisal rails5-postgres-redis-activesupport rake spec:railsredis_activesupport' declare 'bundle exec appraisal rails5-postgres-sidekiq rake spec:railsactivejob' declare 'bundle exec appraisal rails5-postgres rake spec:railsdisableenv' declare 'bundle exec appraisal rails5-postgres rake spec:railsautoinstrument' declare 'bundle exec appraisal rails6-mysql2 rake test:rails' declare 'bundle exec appraisal rails6-postgres rake test:rails' declare 'bundle exec appraisal rails6-postgres-redis rake spec:railsredis' - declare 'bundle exec appraisal rails6-postgres-redis-activesupport rake spec:railsredis' + declare 'bundle exec appraisal rails6-postgres-redis-activesupport rake spec:railsredis_activesupport' declare 'bundle exec appraisal rails6-postgres-sidekiq rake spec:railsactivejob' declare 'bundle exec appraisal rails6-postgres rake spec:railsdisableenv' declare 'bundle exec appraisal rails6-postgres rake spec:railsautoinstrument' @@ -810,14 +818,14 @@ task :ci do declare 'bundle exec appraisal rails5-mysql2 rake test:rails' declare 'bundle exec appraisal rails5-postgres rake test:rails' declare 'bundle exec appraisal rails5-postgres-redis rake spec:railsredis' - declare 'bundle exec appraisal rails5-postgres-redis-activesupport rake spec:railsredis' + declare 'bundle exec appraisal rails5-postgres-redis-activesupport rake spec:railsredis_activesupport' declare 'bundle exec appraisal rails5-postgres-sidekiq rake spec:railsactivejob' declare 'bundle exec appraisal rails5-postgres rake spec:railsdisableenv' declare 'bundle exec appraisal rails5-postgres rake spec:railsautoinstrument' declare 'bundle exec appraisal rails6-mysql2 rake test:rails' declare 'bundle exec appraisal rails6-postgres rake test:rails' declare 'bundle exec appraisal rails6-postgres-redis rake spec:railsredis' - declare 'bundle exec appraisal rails6-postgres-redis-activesupport rake spec:railsredis' + declare 'bundle exec appraisal rails6-postgres-redis-activesupport rake spec:railsredis_activesupport' declare 'bundle exec appraisal rails6-postgres-sidekiq rake spec:railsactivejob' declare 'bundle exec appraisal rails6-postgres rake spec:railsdisableenv' declare 'bundle exec appraisal rails6-postgres rake spec:railsautoinstrument' diff --git a/spec/ddtrace/contrib/rails/redis_cache_spec.rb b/spec/ddtrace/contrib/rails/redis_cache_spec.rb index 30e110903a..878f614c38 100644 --- a/spec/ddtrace/contrib/rails/redis_cache_spec.rb +++ b/spec/ddtrace/contrib/rails/redis_cache_spec.rb @@ -26,6 +26,22 @@ allow(ENV).to receive(:[]).and_call_original allow(ENV).to receive(:[]).with('REDIS_URL').and_return("redis://#{host}:#{port}") + + if ENV['EXPECT_RAILS_ACTIVESUPPORT'] == 'true' + require 'redis-activesupport' + + expect(cache_store_name).to( + eq('redis_store'), + 'Tests are running with ENV["EXPECT_RAILS_ACTIVESUPPORT"] = true but the test application is not using ' \ + 'the rails-activesupport gem.' + ) + else + expect(cache_store_name).to( + eq('redis_cache_store'), + 'Tests are running without ENV["EXPECT_RAILS_ACTIVESUPPORT"] being set but the test application is not using ' \ + 'the rails built-in redis support.' + ) + end end before { app } @@ -43,8 +59,7 @@ let(:key) { 'custom-key' } let(:cache_store_name) do - if Gem.loaded_specs['redis-activesupport'] \ - && Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new('5.2') + if Gem.loaded_specs['redis-activesupport'] 'redis_store' else 'redis_cache_store' @@ -53,7 +68,7 @@ let(:cache) { Rails.cache } - after { cache.clear } + after { cache && cache.clear } shared_examples 'reader method' do |method| subject(:read) { cache.public_send(method, key) } diff --git a/spec/ddtrace/contrib/rails/support/rails5.rb b/spec/ddtrace/contrib/rails/support/rails5.rb index 9bef901a7c..d3d479c237 100644 --- a/spec/ddtrace/contrib/rails/support/rails5.rb +++ b/spec/ddtrace/contrib/rails/support/rails5.rb @@ -28,7 +28,12 @@ def config.database_configuration klass.send(:define_method, :initialize) do |*args| super(*args) - redis_cache = [:redis_cache_store, { url: ENV['REDIS_URL'] }] + redis_cache = + if Gem.loaded_specs['redis-activesupport'] + [:redis_store, { url: ENV['REDIS_URL'] }] + else + [:redis_cache_store, { url: ENV['REDIS_URL'] }] + end file_cache = [:file_store, '/tmp/ddtrace-rb/cache/'] config.secret_key_base = 'f624861242e4ccf20eacb6bb48a886da' diff --git a/spec/ddtrace/contrib/rails/support/rails6.rb b/spec/ddtrace/contrib/rails/support/rails6.rb index 9bbef71a83..327158add2 100644 --- a/spec/ddtrace/contrib/rails/support/rails6.rb +++ b/spec/ddtrace/contrib/rails/support/rails6.rb @@ -28,11 +28,17 @@ def config.database_configuration klass.send(:define_method, :initialize) do |*args| super(*args) - redis_cache = [:redis_cache_store, { url: ENV['REDIS_URL'] }] + redis_cache = + if Gem.loaded_specs['redis-activesupport'] + [:redis_store, { url: ENV['REDIS_URL'] }] + else + [:redis_cache_store, { url: ENV['REDIS_URL'] }] + end file_cache = [:file_store, '/tmp/ddtrace-rb/cache/'] config.load_defaults '6.0' config.secret_key_base = 'f624861242e4ccf20eacb6bb48a886da' + config.active_record.cache_versioning = false if Gem.loaded_specs['redis-activesupport'] config.cache_store = ENV['REDIS_URL'] ? redis_cache : file_cache config.eager_load = false config.consider_all_requests_local = true