Skip to content

Commit

Permalink
Merge pull request #1641 from DataDog/ivoanjo/fix-misleading-redis-ac…
Browse files Browse the repository at this point in the history
…tivesupport-tests

Fix misleading and missing redis-activesupport tests
  • Loading branch information
ivoanjo authored Aug 10, 2021
2 parents 66396aa + a81bc06 commit f7431ce
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 25 deletions.
14 changes: 10 additions & 4 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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'
Expand All @@ -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
Expand Down
40 changes: 24 additions & 16 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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(' ')
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
21 changes: 18 additions & 3 deletions spec/ddtrace/contrib/rails/redis_cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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'
Expand All @@ -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) }
Expand Down
7 changes: 6 additions & 1 deletion spec/ddtrace/contrib/rails/support/rails5.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 7 additions & 1 deletion spec/ddtrace/contrib/rails/support/rails6.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f7431ce

Please sign in to comment.