Skip to content

Commit dbb559f

Browse files
committed
Remove deadlock retry artifacts.
1 parent f711dd0 commit dbb559f

File tree

2 files changed

+0
-82
lines changed

2 files changed

+0
-82
lines changed

lib/active_record/sqlserver_base.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,5 @@ def self.sqlserver_connection(config) #:nodoc:
1818
ConnectionAdapters::SQLServerAdapter.new(nil, logger, nil, config.merge(mode: mode))
1919
end
2020

21-
def self.did_retry_sqlserver_connection(connection, count)
22-
logger.info "CONNECTION RETRY: #{connection.class.name} retry ##{count}."
23-
end
24-
25-
def self.did_lose_sqlserver_connection(connection)
26-
logger.info "CONNECTION LOST: #{connection.class.name}"
27-
end
28-
2921
end
3022
end

test/cases/connection_test_sqlserver.rb

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -109,72 +109,6 @@ class ConnectionTestSQLServer < ActiveRecord::TestCase
109109
assert connection.active?
110110
end
111111

112-
describe 'with a deadlock victim exception 1205' do
113-
114-
describe 'outside a transaction' do
115-
116-
before do
117-
@query = "SELECT 1 as [one]"
118-
@expected = connection.execute(@query)
119-
# Execute the query to get a handle of the expected result, which
120-
# will be returned after a simulated deadlock victim (1205).
121-
raw_conn = connection.raw_connection
122-
stubbed_handle = raw_conn.execute(@query)
123-
connection.send(:finish_statement_handle, stubbed_handle)
124-
raw_conn.stubs(:execute).raises(deadlock_victim_exception(@query)).then.returns(stubbed_handle)
125-
end
126-
127-
it 'raise ActiveRecord::DeadlockVictim' do
128-
assert_raise(ActiveRecord::DeadlockVictim) do
129-
assert_equal @expected, connection.execute(@query)
130-
end
131-
end
132-
133-
end
134-
135-
describe 'within a transaction' do
136-
137-
before do
138-
@query = "SELECT 1 as [one]"
139-
@expected = connection.execute(@query)
140-
# We "stub" the execute method to simulate raising a deadlock victim exception once.
141-
connection.class.class_eval do
142-
def execute_with_deadlock_exception(sql, *args)
143-
if !@raised_deadlock_exception && sql == "SELECT 1 as [one]"
144-
sql = "RAISERROR('Transaction (Process ID #{Process.pid}) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.: #{sql}', 13, 1)"
145-
@raised_deadlock_exception = true
146-
elsif @raised_deadlock_exception == true && sql =~ /RAISERROR\('Transaction \(Process ID \d+\) was deadlocked on lock resources with another process and has been chosen as the deadlock victim\. Rerun the transaction\.: SELECT 1 as \[one\]', 13, 1\)/
147-
sql = "SELECT 1 as [one]"
148-
end
149-
execute_without_deadlock_exception(sql, *args)
150-
end
151-
alias :execute_without_deadlock_exception :execute
152-
alias :execute :execute_with_deadlock_exception
153-
end
154-
end
155-
156-
after do
157-
# Cleanup the "stubbed" execute method.
158-
connection.class.class_eval do
159-
alias :execute :execute_without_deadlock_exception
160-
remove_method :execute_with_deadlock_exception
161-
remove_method :execute_without_deadlock_exception
162-
end
163-
connection.send(:remove_instance_variable, :@raised_deadlock_exception)
164-
end
165-
166-
it 'raise ActiveRecord::DeadlockVictim if retry disabled' do
167-
assert_raise(ActiveRecord::DeadlockVictim) do
168-
ActiveRecord::Base.transaction do
169-
assert_equal @expected, connection.execute(@query)
170-
end
171-
end
172-
end
173-
174-
end
175-
176-
end if connection_mode_dblib? # Since it is easier to test, but feature should work in ODBC too.
177-
178112
end
179113

180114

@@ -205,12 +139,4 @@ def assert_all_odbc_statements_used_are_closed(&block)
205139
GC.enable
206140
end
207141

208-
def deadlock_victim_exception(sql)
209-
require 'tiny_tds/error'
210-
error = TinyTds::Error.new("Transaction (Process ID #{Process.pid}) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.: #{sql}")
211-
error.severity = 13
212-
error.db_error_number = 1205
213-
error
214-
end
215-
216142
end

0 commit comments

Comments
 (0)