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

Ensure sqlite3_mem transaction tests run in memory #39158

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 11 additions & 7 deletions activerecord/test/cases/adapters/sqlite3/transaction_test.rb
Expand Up @@ -10,7 +10,7 @@ class SQLite3TransactionTest < ActiveRecord::SQLite3TestCase
end

test "shared_cached? is false when cache-mode is disabled" do
flags =::SQLite3::Constants::Open::READWRITE | SQLite3::Constants::Open::CREATE
flags = ::SQLite3::Constants::Open::READWRITE | SQLite3::Constants::Open::CREATE

with_connection(flags: flags) do |conn|
assert_not_predicate(conn, :shared_cache?)
Expand Down Expand Up @@ -102,15 +102,19 @@ def read_uncommitted?(conn)
end

def shared_cache_flags
::SQLite3::Constants::Open::READWRITE | SQLite3::Constants::Open::CREATE | ::SQLite3::Constants::Open::SHAREDCACHE | ::SQLite3::Constants::Open::URI
::SQLite3::Constants::Open::READWRITE | SQLite3::Constants::Open::CREATE | ::SQLite3::Constants::Open::SHAREDCACHE
end

def with_connection(options = {})
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")
conn_options = options.reverse_merge(
database: in_memory_db? ? "test/db/file::memory:" : db_config.database
)
conn = ActiveRecord::Base.sqlite3_connection(conn_options)
options = options.dup
if in_memory_db?
options[:database] ||= "file::memory:"
options[:flags] = options[:flags].to_i | ::SQLite3::Constants::Open::URI | ::SQLite3::Constants::Open::READWRITE
else
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")
options[:database] ||= db_config.database
end
conn = ActiveRecord::Base.sqlite3_connection(options)

yield(conn)
ensure
Expand Down