Make various minor fixes to the Active Record test suite
Extracted from: https://github.com/rails/rails/pull/50999 - Make fixtures setup and teardown methods private. - Don't run adapter thread safety tests with sqlite3_mem - Make foreign_key_tests more resilient to leaked state - Use `exit!` in fork to avoid `at_exit` side effects. - Disable transactional fixtures in tests that do a lot of low level assertions on connections or connection pools.
This commit is contained in:
parent
bfcfede66a
commit
29fe34486d
@ -110,7 +110,8 @@ def uses_transaction?(method)
|
||||
end
|
||||
end
|
||||
|
||||
def fixture_path # :nodoc:
|
||||
private
|
||||
def fixture_path
|
||||
ActiveRecord.deprecator.warn(<<~WARNING)
|
||||
TestFixtures#fixture_path is deprecated and will be removed in Rails 7.2. Use #fixture_paths instead.
|
||||
If multiple fixture paths have been configured with #fixture_paths, then #fixture_path will just return
|
||||
@ -167,7 +168,6 @@ def teardown_fixtures
|
||||
ActiveRecord::Base.connection_handler.clear_active_connections!(:all)
|
||||
end
|
||||
|
||||
private
|
||||
def setup_transactional_fixtures
|
||||
setup_shared_connection_pool
|
||||
|
||||
|
@ -820,6 +820,7 @@ class AdapterThreadSafetyTest < ActiveRecord::TestCase
|
||||
@threads.each(&:kill)
|
||||
end
|
||||
|
||||
unless in_memory_db?
|
||||
test "#active? is synchronized" do
|
||||
threads(2, 25) { @connection.select_all("SELECT 1") }
|
||||
threads(2, 25) { @connection.verify! }
|
||||
@ -834,6 +835,7 @@ class AdapterThreadSafetyTest < ActiveRecord::TestCase
|
||||
|
||||
join
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def join
|
||||
|
@ -1555,6 +1555,7 @@ def test_marshal_between_processes
|
||||
post.comments.build
|
||||
wr.write Marshal.dump(post)
|
||||
wr.close
|
||||
exit!(0)
|
||||
end
|
||||
|
||||
wr.close
|
||||
|
@ -6,6 +6,11 @@
|
||||
module ActiveRecord
|
||||
module ConnectionAdapters
|
||||
module ConnectionPoolTests
|
||||
def self.included(test)
|
||||
super
|
||||
test.use_transactional_tests = false
|
||||
end
|
||||
|
||||
attr_reader :pool
|
||||
|
||||
def setup
|
||||
|
@ -674,20 +674,30 @@ def change
|
||||
end
|
||||
|
||||
def test_add_foreign_key_is_reversible
|
||||
@connection.drop_table("cities", if_exists: true)
|
||||
@connection.drop_table("houses", if_exists: true)
|
||||
|
||||
migration = CreateCitiesAndHousesMigration.new
|
||||
silence_stream($stdout) { migration.migrate(:up) }
|
||||
assert_equal 1, @connection.foreign_keys("houses").size
|
||||
ensure
|
||||
silence_stream($stdout) { migration.migrate(:down) }
|
||||
ensure
|
||||
@connection.drop_table("cities", if_exists: true)
|
||||
@connection.drop_table("houses", if_exists: true)
|
||||
end
|
||||
|
||||
def test_foreign_key_constraint_is_not_cached_incorrectly
|
||||
@connection.drop_table("cities", if_exists: true)
|
||||
@connection.drop_table("houses", if_exists: true)
|
||||
|
||||
migration = CreateCitiesAndHousesMigration.new
|
||||
silence_stream($stdout) { migration.migrate(:up) }
|
||||
output = dump_table_schema "houses"
|
||||
assert_match %r{\s+add_foreign_key "houses",.+on_delete: :cascade$}, output
|
||||
ensure
|
||||
silence_stream($stdout) { migration.migrate(:down) }
|
||||
ensure
|
||||
@connection.drop_table("cities", if_exists: true)
|
||||
@connection.drop_table("houses", if_exists: true)
|
||||
end
|
||||
|
||||
class CreateSchoolsAndClassesMigration < ActiveRecord::Migration::Current
|
||||
|
@ -6,6 +6,8 @@
|
||||
require "models/zine"
|
||||
|
||||
class TestFixturesTest < ActiveRecord::TestCase
|
||||
self.use_transactional_tests = false
|
||||
|
||||
setup do
|
||||
@klass = Class.new
|
||||
@klass.include(ActiveRecord::TestFixtures)
|
||||
|
Loading…
Reference in New Issue
Block a user