X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/252c2f70225595312151bcf77ee7c8f5aac0c831..7c98b41cc89068d049a18f8738276f19cd47095e:/vendor/plugins/deadlock_retry/test/deadlock_retry_test.rb diff --git a/vendor/plugins/deadlock_retry/test/deadlock_retry_test.rb b/vendor/plugins/deadlock_retry/test/deadlock_retry_test.rb index db0f6195d..7124391f8 100644 --- a/vendor/plugins/deadlock_retry/test/deadlock_retry_test.rb +++ b/vendor/plugins/deadlock_retry/test/deadlock_retry_test.rb @@ -20,8 +20,21 @@ require 'test/unit' require "#{File.dirname(__FILE__)}/../lib/deadlock_retry" class MockModel - def self.transaction(*objects, &block) - block.call + @@open_transactions = 0 + + def self.transaction(*objects) + @@open_transactions += 1 + yield + ensure + @@open_transactions -= 1 + end + + def self.open_transactions + @@open_transactions + end + + def self.connection + self end def self.logger @@ -62,4 +75,21 @@ class DeadlockRetryTest < Test::Unit::TestCase MockModel.transaction { raise ActiveRecord::StatementInvalid, "Something else" } end end + + def test_error_in_nested_transaction_should_retry_outermost_transaction + tries = 0 + errors = 0 + + MockModel.transaction do + tries += 1 + MockModel.transaction do + MockModel.transaction do + errors += 1 + raise ActiveRecord::StatementInvalid, "MySQL::Error: Lock wait timeout exceeded" unless errors > 3 + end + end + end + + assert_equal 4, tries + end end