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

Conversation

jonathanhefner
Copy link
Member

@jonathanhefner jonathanhefner commented May 6, 2020

SQLite3 does not recognize paths as file URIs unless the SQLite3::Constants::Open::URI flag is set. Therefore, without this flag, a path like "file::memory:" is interpreted as a filename, causing a "file::memory:" file to be created and used as the database. Most tests in SQLite3TransactionTest picked up this flag from shared_cache_flags, but a few did not. Because those tests were creating a file, the path was changed in #38620 such that it no longer pointed to an in-memory database.

This commit restores the database path as "file::memory:" and ensures the URI flag is set whenever in_memory_db? is true.


I discovered this issue when I ran:

ARCONN=sqlite3_mem bin/test test/cases/adapters/sqlite3/transaction_test.rb

more than once, and received the following error:

Error:
SQLite3TransactionTest#test_opens_a_`read_uncommitted`_transaction:
ActiveRecord::StatementInvalid: SQLite3::SQLException: table "zines" already exists

After some digging, I found this discussion: #38620 (comment)

This PR resolves that discussion, though there may be a larger discussion to be had about enabling this flag by default.

SQLite3 does not recognize paths as file URIs unless the
`SQLite3::Constants::Open::URI` flag is set.  Therefore, without this
flag, a path like "file::memory:" is interpreted as a filename, causing
a "file::memory:" file to be created and used as the database.  Most
tests in `SQLite3TransactionTest` picked up this flag from
`shared_cache_flags`, but a few did not.  Because those tests were
creating a file, the path was changed in rails#38620 such that it no longer
pointed to an in-memory database.

This commit restores the database path as "file::memory:" and ensures
the URI flag is set whenever `in_memory_db?` is true.
@jonathanhefner jonathanhefner force-pushed the sqlite3_mem-transaction-tests-in-memory branch from 45a4a8f to c806be3 Compare May 6, 2020 01:07
@rafaelfranca rafaelfranca merged commit 46f9053 into rails:master May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants