Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redefine isolation level method as MSSSQL resets isolation after transaction #1324

Merged
merged 3 commits into from
Apr 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions test/cases/coerced_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1842,6 +1842,22 @@ class TransactionIsolationTest < ActiveRecord::TestCase

# I really need some help understanding this one.
coerce_tests! %r{repeatable read}

private

# Need to handle the resetting of the isolation level in the adapter by `SQLServerRealTransaction#commit`.
# MySQL & PostgreSQL do not reset the connection and SQLite does support transaction isolation. After that we
# can assert the number of expected isolation level events.
undef_method :assert_begin_isolation_level_event
def assert_begin_isolation_level_event(events, isolation: "READ COMMITTED")
isolation_events = events.select { _1.match(/SET TRANSACTION ISOLATION LEVEL/) }

index_of_reset_starting_isolation_level_event = isolation_events.index("SET TRANSACTION ISOLATION LEVEL READ COMMITTED")
assert index_of_reset_starting_isolation_level_event.present?
isolation_events.delete_at(index_of_reset_starting_isolation_level_event)

assert_equal 1, isolation_events.select { _1.match(/SET TRANSACTION ISOLATION LEVEL #{isolation}/) }.size
end
end

class ViewWithPrimaryKeyTest < ActiveRecord::TestCase
Expand Down