Skip to content

Commit 766b219

Browse files
committed
Fix tests
1 parent a5b8409 commit 766b219

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

test/cases/coerced_tests.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,18 +1845,21 @@ class TransactionIsolationTest < ActiveRecord::TestCase
18451845

18461846
private
18471847

1848-
# Need to handle the resetting of the isolation level in the adapter by `SQLServerRealTransaction#commit`.
1849-
# MySQL & PostgreSQL do not reset the connection and SQLite does support transaction isolation. After that we
1850-
# can assert the number of expected isolation level events.
1848+
# Need to handle the resetting of the isolation level in the adapter by `SQLServerRealTransaction#commit` for each
1849+
# connection pool. After the resetting events have been removed we can assert the number of expected isolation level
1850+
# events. This workaround assumes that the `count` also matches the number of connection pools used in the test.
1851+
# Note: MySQL & PostgreSQL do not reset the connection and SQLite does support transaction isolation.
18511852
undef_method :assert_begin_isolation_level_event
1852-
def assert_begin_isolation_level_event(events, isolation: "READ COMMITTED")
1853+
def assert_begin_isolation_level_event(events, isolation: "READ COMMITTED", count: 1)
18531854
isolation_events = events.select { |event| event.match(/SET TRANSACTION ISOLATION LEVEL/) }
18541855

1855-
index_of_reset_starting_isolation_level_event = isolation_events.index("SET TRANSACTION ISOLATION LEVEL READ COMMITTED")
1856-
assert index_of_reset_starting_isolation_level_event.present?
1857-
isolation_events.delete_at(index_of_reset_starting_isolation_level_event)
1856+
count.times do
1857+
index_of_reset_starting_isolation_level_event = isolation_events.index("SET TRANSACTION ISOLATION LEVEL READ COMMITTED")
1858+
assert index_of_reset_starting_isolation_level_event.present?
1859+
isolation_events.delete_at(index_of_reset_starting_isolation_level_event)
1860+
end
18581861

1859-
assert_equal 1, isolation_events.count { |event| event.match(/SET TRANSACTION ISOLATION LEVEL #{isolation}/) }
1862+
assert_equal count, isolation_events.count { |event| event.match(/SET TRANSACTION ISOLATION LEVEL #{isolation}/) }
18601863
end
18611864
end
18621865

0 commit comments

Comments
 (0)