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

Add Rails 7.2 compatibility #167

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Add Rails 7.2 compatibility #167

wants to merge 6 commits into from

Conversation

rosston
Copy link
Member

@rosston rosston commented Sep 25, 2024

Hopefully takes care of #164.

There are 3 significant changes in this PR:

1. Remove lock_thread on connection pool

The commit that added lock_thread (f638085) notes that

Transaction management is largely ripped straight out of test_fixtures.rb in Rails

The commit that adds lock_thread in Rails has some helpful context:

When a system test starts Puma spins up one thread and Capybara spins up another thread. Because of this when tests are run the database cannot see what was inserted into the database on teardown. This is because there are two threads using two different connections.

This change uses the statement cache to lock the threads to using a single connection ID instead of each not being able to see each other.

So lock_thread exists because there are two different threads — Puma and Capybara — trying to access the same database but not necessarily seeing the same thing. But! cypress-rails doesn't use Capybara, and more importantly, it doesn't use tests or a test runner written in Ruby at all, so there's only one thread trying to use the database. So we don't need all this thread locking stuff. So let's remove it to make things more compatible with Rails 7.2. Hat tip to @tinney for saying this to my face before I came around to it. 😅

I think I'm right about this, but I plan to do a pre-release with these changes and try to get some folks from #164 to do real world testing.

(Aside for breadcrumbs, the commits that remove lock_thread are rails/rails@26de25d and rails/rails@1dcb411.)

2. Use #lease_connection instead of #connection (when available)

This change is ripped straight from #165, so thank you to @ledermann! 🙇

3. Build and test the example app with both Rails 7.1 and 7.2

Rails 7.1 is still supported, and I wouldn't be surprised if we end up with 3 simultaneously supported versions at some point: 7.1, 7.2, and 8.0. I'd like the tests to cover all versions we support so that we can feel more confident in changes.

I went about this with symlinked Gemfiles (hat tip to @jasonkarns on this one) with some logic in Gemfile to do the right Rails version, paired with some use of BUNDLE_GEMFILE.

rosston and others added 6 commits September 20, 2024 21:49
The commit that added
lock_thread (f638085) notes that
> Transaction management is largely ripped straight out of
> test_fixtures.rb in Rails

The commit that adds lock_thread in Rails --
rails/rails@d6466be
-- has some helpful context:
> When a system test starts Puma spins up one thread and Capybara spins
> up another thread. Because of this when tests are run the database
> cannot see what was inserted into the database on teardown. This is
> because there are two threads using two different connections.

> This change uses the statement cache to lock the threads to using a
> single connection ID instead of each not being able to see each other.

So lock_thread exists because there are two different threads -- Puma
and Capybara -- trying to access the same database but not necessarily
seeing the same thing. But! cypress-rails doesn't use Capybara, and more
importantly, it doesn't use tests or a test runner written in Ruby at
all, so there's only _one_ thread trying to use the database. So we
don't need all this thread locking stuff. So let's remove it to make
things more compatible with Rails 7.2.
Taken from #165, hence
the coauthor credit.

Co-authored-by: Georg Ledermann <[email protected]>
Use symlinks for multiple Gemfiles.
This prevents us from installing gems in the example app that aren't
needed by a different gemfile.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant