diff options
author | Matthew Draper <matthew@trebex.net> | 2017-11-25 17:53:57 +1030 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-25 17:53:57 +1030 |
commit | 3313912de1814ff4698e050c414940f004af93b0 (patch) | |
tree | 0b79a26d9598bab22c4a152ccbe56862d7e2bcfc /activerecord/test/cases | |
parent | 2ec9c532cbbdbe636a17411db3f9de47ca6a81c1 (diff) | |
parent | f32cff5563f2188e657aa2fd9f8513f0da4a49ca (diff) | |
download | rails-3313912de1814ff4698e050c414940f004af93b0.tar.gz rails-3313912de1814ff4698e050c414940f004af93b0.tar.bz2 rails-3313912de1814ff4698e050c414940f004af93b0.zip |
Merge pull request #31173 from matthewd/connection-fork-safety
Improve AR connection fork safety
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/connection_adapters/connection_handler_test.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/activerecord/test/cases/connection_adapters/connection_handler_test.rb b/activerecord/test/cases/connection_adapters/connection_handler_test.rb index 74d0ed348e..cae74a2b9b 100644 --- a/activerecord/test/cases/connection_adapters/connection_handler_test.rb +++ b/activerecord/test/cases/connection_adapters/connection_handler_test.rb @@ -1,10 +1,15 @@ # frozen_string_literal: true require "cases/helper" +require "models/person" module ActiveRecord module ConnectionAdapters class ConnectionHandlerTest < ActiveRecord::TestCase + self.use_transactional_tests = false + + fixtures :people + def setup @handler = ConnectionHandler.new @spec_name = "primary" @@ -139,6 +144,33 @@ module ActiveRecord rd.close end + def test_forked_child_doesnt_mangle_parent_connection + object_id = ActiveRecord::Base.connection.object_id + assert ActiveRecord::Base.connection.active? + + rd, wr = IO.pipe + rd.binmode + wr.binmode + + pid = fork { + rd.close + if ActiveRecord::Base.connection.active? + wr.write Marshal.dump ActiveRecord::Base.connection.object_id + end + wr.close + + exit # allow finalizers to run + } + + wr.close + + Process.waitpid pid + assert_not_equal object_id, Marshal.load(rd.read) + rd.close + + assert_equal 3, ActiveRecord::Base.connection.select_value("SELECT COUNT(*) FROM people") + end + def test_retrieve_connection_pool_copies_schema_cache_from_ancestor_pool @pool.schema_cache = @pool.connection.schema_cache @pool.schema_cache.add("posts") |