Guest User

Untitled

a guest
Feb 19th, 2018
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. From 668d43b053f5f651b66357b3599e4bdec2c4a9e3 Mon Sep 17 00:00:00 2001
  2. From: Nick Sieger <nick@nicksieger.com>
  3. Date: Thu, 4 Sep 2008 15:16:29 +0200
  4. Subject: [PATCH] Default connection allow_concurrency to false (for PostgreSQL)
  5.  
  6. ---
  7. .../abstract/connection_pool.rb | 3 +--
  8. activerecord/lib/active_record/test_case.rb | 15 +++++++++++++++
  9. activerecord/test/cases/locking_test.rb | 2 ++
  10. activerecord/test/cases/transactions_test.rb | 2 ++
  11. 4 files changed, 20 insertions(+), 2 deletions(-)
  12.  
  13. diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
  14. index 6b4bc25..5806dea 100644
  15. --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
  16. +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
  17. @@ -164,8 +164,7 @@ module ActiveRecord
  18.  
  19. private
  20. def new_connection
  21. - config = spec.config.reverse_merge(:allow_concurrency => true)
  22. - ActiveRecord::Base.send(spec.adapter_method, config)
  23. + ActiveRecord::Base.send(spec.adapter_method, spec.config)
  24. end
  25.  
  26. def current_connection_id #:nodoc:
  27. diff --git a/activerecord/lib/active_record/test_case.rb b/activerecord/lib/active_record/test_case.rb
  28. index ffaa412..eabf06f 100644
  29. --- a/activerecord/lib/active_record/test_case.rb
  30. +++ b/activerecord/lib/active_record/test_case.rb
  31. @@ -43,5 +43,20 @@ module ActiveRecord
  32. def assert_no_queries(&block)
  33. assert_queries(0, &block)
  34. end
  35. +
  36. + def self.use_concurrent_connections
  37. + setup :connection_allow_concurrency_setup
  38. + teardown :connection_allow_concurrency_teardown
  39. + end
  40. +
  41. + def connection_allow_concurrency_setup
  42. + @connection = ActiveRecord::Base.remove_connection
  43. + ActiveRecord::Base.establish_connection(@connection.merge({:allow_concurrency => true}))
  44. + end
  45. +
  46. + def connection_allow_concurrency_teardown
  47. + ActiveRecord::Base.clear_all_connections!
  48. + ActiveRecord::Base.establish_connection(@connection)
  49. + end
  50. end
  51. end
  52. diff --git a/activerecord/test/cases/locking_test.rb b/activerecord/test/cases/locking_test.rb
  53. index bbe8582..0a14b1d 100644
  54. --- a/activerecord/test/cases/locking_test.rb
  55. +++ b/activerecord/test/cases/locking_test.rb
  56. @@ -257,6 +257,8 @@ unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :OpenBaseAdapter)
  57. end
  58.  
  59. if current_adapter?(:PostgreSQLAdapter, :OracleAdapter)
  60. + use_concurrent_connections
  61. +
  62. def test_no_locks_no_wait
  63. first, second = duel { Person.find 1 }
  64. assert first.end > second.end
  65. diff --git a/activerecord/test/cases/transactions_test.rb b/activerecord/test/cases/transactions_test.rb
  66. index a8016cd..b12ec36 100644
  67. --- a/activerecord/test/cases/transactions_test.rb
  68. +++ b/activerecord/test/cases/transactions_test.rb
  69. @@ -284,6 +284,8 @@ end
  70.  
  71. if current_adapter?(:PostgreSQLAdapter)
  72. class ConcurrentTransactionTest < TransactionTest
  73. + use_concurrent_connections
  74. +
  75. # This will cause transactions to overlap and fail unless they are performed on
  76. # separate database connections.
  77. def test_transaction_per_thread
  78. --
  79. 1.5.6
Add Comment
Please, Sign In to add comment