Skip to content

Commit fed3125

Browse files
authored
Merge pull request rails#49470 from rails/rm-eager-load-model-schema
Load the model schema when running test in eager load context
2 parents fafb6de + 1f0262a commit fed3125

File tree

21 files changed

+89
-38
lines changed

21 files changed

+89
-38
lines changed

actionmailbox/test/test_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
ENV["RAILS_ENV"] = "test"
66
ENV["RAILS_INBOUND_EMAIL_PASSWORD"] = "tbsy84uSV1Kt3ZJZELY2TmShPRs91E3yL4tzf96297vBCkDWgL"
77

8+
require_relative "../../tools/test_common"
9+
810
require_relative "../test/dummy/config/environment"
911
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)]
1012
require "rails/test_help"
@@ -53,5 +55,3 @@ def bounce(to:)
5355
end
5456
end
5557
end
56-
57-
require_relative "../../tools/test_common"

activejob/test/helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require_relative "../../tools/test_common"
4+
35
require "active_support/testing/strict_warnings"
46
require "active_job"
57
require "support/job_buffer"
@@ -18,8 +20,6 @@
1820

1921
require "active_support/testing/autorun"
2022

21-
require_relative "../../tools/test_common"
22-
2323
def adapter_is?(*adapter_class_symbols)
2424
adapter_class_symbols.map(&:to_s).include? ActiveJob::Base.queue_adapter_name
2525
end

activejob/test/support/integration/adapters/backburner.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def setup
99
end
1010
unless can_run?
1111
puts "Cannot run integration tests for backburner. To be able to run integration tests for backburner you need to install and start beanstalkd.\n"
12-
status = ENV["CI"] ? false : true
12+
status = ENV["BUILDKITE"] ? false : true
1313
exit status
1414
end
1515
end

activejob/test/support/integration/adapters/queue_classic.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def start_workers
4141

4242
rescue PG::ConnectionBad
4343
puts "Cannot run integration tests for queue_classic. To be able to run integration tests for queue_classic you need to install and start postgresql.\n"
44-
status = ENV["CI"] ? false : true
44+
status = ENV["BUILDKITE"] ? false : true
4545
exit status
4646
end
4747

activejob/test/support/integration/adapters/resque.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def setup
77
Resque.logger = Rails.logger
88
unless can_run?
99
puts "Cannot run integration tests for resque. To be able to run integration tests for resque you need to install and start redis.\n"
10-
status = ENV["CI"] ? false : true
10+
status = ENV["BUILDKITE"] ? false : true
1111
exit status
1212
end
1313
end

activejob/test/support/integration/adapters/sidekiq.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def setup
1010
ActiveJob::Base.queue_adapter = :sidekiq
1111
unless can_run?
1212
puts "Cannot run integration tests for sidekiq. To be able to run integration tests for sidekiq you need to install and start redis.\n"
13-
status = ENV["CI"] ? false : true
13+
status = ENV["BUILDKITE"] ? false : true
1414
exit status
1515
end
1616
end

activejob/test/support/integration/adapters/sneakers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def setup
1818
log: Rails.root.join("log/sneakers.log").to_s
1919
unless can_run?
2020
puts "Cannot run integration tests for sneakers. To be able to run integration tests for sneakers you need to install and start rabbitmq.\n"
21-
status = ENV["CI"] ? false : true
21+
status = ENV["BUILDKITE"] ? false : true
2222
exit status
2323
end
2424
end

activerecord/lib/active_record/model_schema.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,20 @@ def reset_column_information
553553
initialize_find_by_cache
554554
end
555555

556+
def load_schema # :nodoc:
557+
return if schema_loaded?
558+
@load_schema_monitor.synchronize do
559+
return if @columns_hash
560+
561+
load_schema!
562+
563+
@schema_loaded = true
564+
rescue
565+
reload_schema_from_cache # If the schema loading failed half way through, we must reset the state.
566+
raise
567+
end
568+
end
569+
556570
protected
557571
def initialize_load_schema_monitor
558572
@load_schema_monitor = Monitor.new
@@ -594,20 +608,6 @@ def schema_loaded?
594608
defined?(@schema_loaded) && @schema_loaded
595609
end
596610

597-
def load_schema
598-
return if schema_loaded?
599-
@load_schema_monitor.synchronize do
600-
return if @columns_hash
601-
602-
load_schema!
603-
604-
@schema_loaded = true
605-
rescue
606-
reload_schema_from_cache # If the schema loading failed half way through, we must reset the state.
607-
raise
608-
end
609-
end
610-
611611
def load_schema!
612612
unless table_name
613613
raise ActiveRecord::TableNotSpecified, "#{self} has no table configured. Set one with #{self}.table_name="

activerecord/test/support/connection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def self.connect
2222
ActiveRecord.async_query_executor = :global_thread_pool
2323
puts "Using #{connection_name}"
2424

25-
if ENV["CI"]
25+
if ENV["BUILDKITE"]
2626
ActiveRecord::Base.logger = nil
2727
else
2828
ActiveRecord::Base.logger = ActiveSupport::Logger.new("debug.log", 1, 100.megabytes)

activestorage/test/analyzer/image_analyzer/image_magick_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def analyze_with_image_magick
6565

6666
yield
6767
rescue LoadError
68-
ENV["CI"] ? raise : skip("Variant processor image_magick is not installed")
68+
ENV["BUILDKITE"] ? raise : skip("Variant processor image_magick is not installed")
6969
ensure
7070
ActiveStorage.variant_processor = previous_processor
7171
end

0 commit comments

Comments
 (0)