From 45d4179b1e990bf4ffabefa0b59230d5e30b9eac Mon Sep 17 00:00:00 2001 From: Peter Solnica Date: Thu, 17 Oct 2024 07:48:26 +0000 Subject: [PATCH] WIP --- sentry-rails/spec/dummy/test_rails_app/app.rb | 107 ++++++++++-------- 1 file changed, 57 insertions(+), 50 deletions(-) diff --git a/sentry-rails/spec/dummy/test_rails_app/app.rb b/sentry-rails/spec/dummy/test_rails_app/app.rb index e64e68c7d..cd48b50ed 100644 --- a/sentry-rails/spec/dummy/test_rails_app/app.rb +++ b/sentry-rails/spec/dummy/test_rails_app/app.rb @@ -42,74 +42,81 @@ class TestApp < Rails::Application # require files and defined relevant setup methods for the Rails version require "dummy/test_rails_app/configs/#{FILE_NAME}" -def make_basic_app(&block) +def measure_elapsed_time(label) start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - _make_basic_app(&block) + yield end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - elapsed_time = end_time - start_time - puts "MAKE BASIC APP: #{elapsed_time} seconds" + puts "#{label}: #{end_time - start_time} seconds" end -def _make_basic_app(&block) - run_pre_initialize_cleanup +def make_basic_app(&block) + measure_elapsed_time("Pre-initialize cleanup") do + run_pre_initialize_cleanup + end - app = Class.new(TestApp) do - def self.name - "RailsTestApp" + app = nil + measure_elapsed_time("App class creation") do + app = Class.new(TestApp) do + def self.name + "RailsTestApp" + end end end - app.config.active_support.deprecation = :silence - app.config.action_controller.view_paths = "spec/dummy/test_rails_app" - app.config.hosts = nil - app.config.secret_key_base = "test" - app.config.logger = ActiveSupport::Logger.new(nil) - 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 - - configure_app(app) - - app.routes.append do - get "/exception", to: "hello#exception" - get "/view_exception", to: "hello#view_exception" - get "/view", to: "hello#view" - get "/not_found", to: "hello#not_found" - get "/world", to: "hello#world" - get "/with_custom_instrumentation", to: "hello#with_custom_instrumentation" - resources :posts, only: [:index, :show] do - member do - get :attach + measure_elapsed_time("App configuration") do + app.config.active_support.deprecation = :silence + app.config.action_controller.view_paths = "spec/dummy/test_rails_app" + app.config.hosts = nil + app.config.secret_key_base = "test" + app.config.logger = ActiveSupport::Logger.new(nil) + app.config.eager_load = true + app.config.active_job.queue_adapter = :test + + app.config.eager_load_namespaces.clear + + configure_app(app) + end + + measure_elapsed_time("Route configuration") do + app.routes.append do + get "/exception", to: "hello#exception" + get "/view_exception", to: "hello#view_exception" + get "/view", to: "hello#view" + get "/not_found", to: "hello#not_found" + get "/world", to: "hello#world" + get "/with_custom_instrumentation", to: "hello#with_custom_instrumentation" + resources :posts, only: [:index, :show] do + member do + get :attach + end end + get "500", to: "hello#reporting" + root to: "hello#world" end - get "500", to: "hello#reporting" - root to: "hello#world" end - app.initializer :configure_sentry do - Sentry.init do |config| - config.release = 'beta' - config.dsn = "http://12345:67890@sentry.localdomain: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? + measure_elapsed_time("Sentry initialization") do + app.initializer :configure_sentry do + Sentry.init do |config| + config.release = 'beta' + config.dsn = "http://12345:67890@sentry.localdomain:3000/sentry/42" + config.transport.transport_class = Sentry::DummyTransport + config.background_worker_threads = 0 + config.capture_exception_frame_locals = true + yield(config, app) if block_given? + end end end - app.initialize! + measure_elapsed_time("App initialization") do + app.initialize! + end Rails.application = app - # load application code for the Rails version - require "dummy/test_rails_app/apps/#{FILE_NAME}" + measure_elapsed_time("Loading application code") do + require "dummy/test_rails_app/apps/#{FILE_NAME}" + end Post.all.to_a # to run the sqlte version query first