-
-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
25 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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" | ||
|
@@ -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 |