Permalink
Browse files

Make deadlock-retry plugin work with recent changes to MySQL error me…

…ssages
  • Loading branch information...
1 parent 61712b7 commit d182952c99a906a1172764b46f92abc5b25b1155 @jamis jamis committed Nov 15, 2005
Showing with 7 additions and 7 deletions.
  1. +4 −4 README
  2. +1 −1 lib/deadlock_retry.rb
  3. +2 −2 test/deadlock_retry_test.rb
View
@@ -1,10 +1,10 @@
Deadlock Retry
==============
-Deadlock retry allows the database adapter (currently only tested with the MySQLAdapter) to retry
-transactions that fall into deadlock. It will retry such transactions three times before finally
-failing.
+Deadlock retry allows the database adapter (currently only tested with the
+MySQLAdapter) to retry transactions that fall into deadlock. It will retry
+such transactions three times before finally failing.
-This capability is automatically added to ActiveRecord. No code changes or otherwise is required.
+This capability is automatically added to ActiveRecord. No code changes or otherwise are required.
Copyright (c) 2005 Jamis Buck, released under the MIT license
@@ -44,7 +44,7 @@ def transaction_with_deadlock_handling(*objects, &block)
begin
transaction_without_deadlock_handling(*objects, &block)
rescue ActiveRecord::StatementInvalid => error
- if DEADLOCK_ERROR_MESSAGES.any? { |msg| error.message =~ /^#{msg}/ }
+ if DEADLOCK_ERROR_MESSAGES.any? { |msg| error.message =~ /#{Regexp.escape(msg)}/ }
raise if retry_count >= MAXIMUM_RETRIES_ON_DEADLOCK
retry_count += 1
logger.info "Deadlock detected on retry #{retry_count}, restarting transaction"
@@ -32,8 +32,8 @@ def self.logger
end
class DeadlockRetryTest < Test::Unit::TestCase
- DEADLOCK_ERROR = "Deadlock found when trying to get lock"
- TIMEOUT_ERROR = "Lock wait timeout exceeded"
+ DEADLOCK_ERROR = "MySQL::Error: Deadlock found when trying to get lock"
+ TIMEOUT_ERROR = "MySQL::Error: Lock wait timeout exceeded"
def test_no_errors
assert_equal :success, MockModel.transaction { :success }

0 comments on commit d182952

Please sign in to comment.