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 c8df8cd commit 45d4179
Showing 1 changed file with 57 additions and 50 deletions.
107 changes: 57 additions & 50 deletions sentry-rails/spec/dummy/test_rails_app/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:[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?
measure_elapsed_time("Sentry initialization") do
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
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

Expand Down

0 comments on commit 45d4179

Please sign in to comment.