Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Oct 17, 2024
1 parent 93d8cea commit 7c5b180
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions sentry-rails/spec/dummy/test_rails_app/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,19 @@ class TestApp < Rails::Application
require "dummy/test_rails_app/configs/#{FILE_NAME}"

def make_basic_app(&block)
start_time = Time.now
run_pre_initialize_cleanup
puts "Pre-initialize cleanup took #{Time.now - start_time} seconds"

app_creation_start = Time.now
app = Class.new(TestApp) do
def self.name
"RailsTestApp"
end
end
puts "App creation took #{Time.now - app_creation_start} seconds"

config_start = Time.now
app.config.active_support.deprecation = :silence
app.config.action_controller.view_paths = "spec/dummy/test_rails_app"
app.config.hosts = nil
Expand All @@ -59,15 +64,14 @@ def self.name
app.config.eager_load = true
app.config.active_job.queue_adapter = :test

# Eager load namespaces can be accumulated after repeated initializations and make initialization
# slower after each run
# This is especially obvious in Rails 7.2, because of https://github.com/rails/rails/pull/49987, but other constants's
# accumulation can also cause slowdown
# Because this is not necessary for the test, we can simply clear it here
app.config.eager_load_namespaces.clear
puts "App configuration took #{Time.now - config_start} seconds"

configure_app_start = Time.now
configure_app(app)
puts "configure_app took #{Time.now - configure_app_start} seconds"

routes_start = Time.now
app.routes.append do
get "/exception", to: "hello#exception"
get "/view_exception", to: "hello#view_exception"
Expand All @@ -83,30 +87,41 @@ def self.name
get "500", to: "hello#reporting"
root to: "hello#world"
end
puts "Routes configuration took #{Time.now - routes_start} seconds"

sentry_init_start = Time.now
app.initializer :configure_sentry do
Sentry.init do |config|
config.release = 'beta'
config.dsn = "http://12345:[email protected]:3000/sentry/42"
config.transport.transport_class = Sentry::DummyTransport
# for sending events synchronously
config.background_worker_threads = 0
config.capture_exception_frame_locals = true
yield(config, app) if block_given?
end
end
puts "Sentry initialization took #{Time.now - sentry_init_start} seconds"

app_init_start = Time.now
app.initialize!
puts "App initialization took #{Time.now - app_init_start} seconds"

Rails.application = app

# load application code for the Rails version
require_start = Time.now
require "dummy/test_rails_app/apps/#{FILE_NAME}"
puts "Requiring app file took #{Time.now - require_start} seconds"

Post.all.to_a # to run the sqlte version query first
post_query_start = Time.now
Post.all.to_a
puts "Post query took #{Time.now - post_query_start} seconds"

# and then clear breadcrumbs in case the above query is recorded
Sentry.get_current_scope.clear_breadcrumbs if Sentry.initialized?
if Sentry.initialized?
clear_breadcrumbs_start = Time.now
Sentry.get_current_scope.clear_breadcrumbs
puts "Clearing breadcrumbs took #{Time.now - clear_breadcrumbs_start} seconds"
end

puts "Total time: #{Time.now - start_time} seconds"
app
end

0 comments on commit 7c5b180

Please sign in to comment.