Skip to content

Commit

Permalink
Update rspec
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikspang committed Aug 29, 2024
1 parent 6eaf81b commit 0367db9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
2 changes: 2 additions & 0 deletions sentry-rails/spec/dummy/test_rails_app/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def self.name
app.config.logger = ActiveSupport::Logger.new(nil)
app.config.eager_load = true
app.config.active_job.queue_adapter = :test
app.config.cache_store = :memory_store
app.config.action_controller.perform_caching = true

# Eager load namespaces can be accumulated after repeated initializations and make initialization
# slower after each run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
make_basic_app do |config, app|
config.traces_sample_rate = 1.0
config.rails.tracing_subscribers = [described_class]

app.config.action_controller.perform_caching = true
app.config.cache_store = :memory_store
end
end

Expand All @@ -32,7 +29,10 @@
expect(cache_transaction[:spans][0][:origin]).to eq("auto.cache.rails")
end

#
it "tracks cache increment" do
skip("Tracks on Rails 8.0 for all Cache Stores; Until then only MemCached and Redis Stores.") if Rails.version.to_f < 8.0

Rails.cache.write("my_cache_key", 0)

transaction = Sentry::Transaction.new(sampled: true, hub: Sentry.get_current_hub)
Expand All @@ -41,6 +41,7 @@

transaction.finish

expect(Rails.cache.read("my_cache_key")).to eq(1)
expect(transport.events.count).to eq(1)
cache_transaction = transport.events.first.to_hash
expect(cache_transaction[:type]).to eq("transaction")
Expand All @@ -49,7 +50,10 @@
expect(cache_transaction[:spans][1][:origin]).to eq("auto.cache.rails")
end

#
it "tracks cache decrement" do
skip("Tracks on Rails 8.0 for all Cache Stores; Until then only MemCached and Redis Stores.") if Rails.version.to_f < 8.0

Rails.cache.write("my_cache_key", 0)

transaction = Sentry::Transaction.new(sampled: true, hub: Sentry.get_current_hub)
Expand Down Expand Up @@ -81,6 +85,39 @@
expect(cache_transaction[:spans][0][:origin]).to eq("auto.cache.rails")
end

it "tracks cache delete" do
transaction = Sentry::Transaction.new(sampled: true, hub: Sentry.get_current_hub)
Sentry.get_current_scope.set_span(transaction)

Rails.cache.read("my_cache_key")

transaction.finish

expect(transport.events.count).to eq(1)
cache_transaction = transport.events.first.to_hash
expect(cache_transaction[:type]).to eq("transaction")
expect(cache_transaction[:spans].count).to eq(1)
expect(cache_transaction[:spans][0][:op]).to eq("cache.get")
expect(cache_transaction[:spans][0][:origin]).to eq("auto.cache.rails")
end
it "tracks cache prune" do
transaction = Sentry::Transaction.new(sampled: true, hub: Sentry.get_current_hub)
Sentry.get_current_scope.set_span(transaction)

Rails.cache.write("my_cache_key", 123, expires_in: 0.seconds)

Rails.cache.prune(0)

transaction.finish

expect(transport.events.count).to eq(1)
cache_transaction = transport.events.first.to_hash
expect(cache_transaction[:type]).to eq("transaction")
expect(cache_transaction[:spans].count).to eq(2)
expect(cache_transaction[:spans][1][:op]).to eq("cache.flush")
expect(cache_transaction[:spans][1][:origin]).to eq("auto.cache.rails")
end

it "tracks sets cache hit" do
Rails.cache.write("my_cache_key", "my_cache_value")
transaction = Sentry::Transaction.new(sampled: true, hub: Sentry.get_current_hub)
Expand Down

0 comments on commit 0367db9

Please sign in to comment.