-
-
Notifications
You must be signed in to change notification settings - Fork 329
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
Compatibility with database_cleaner v2 adapter gems #467
Compatibility with database_cleaner v2 adapter gems #467
Conversation
Okay, tests have all completed for the failing test commit. I've checked the output for all the runners, and they are all failing as expected, with the following:
This demonstrates the issue, namely, that the database_cleaner integration will simply stop working without an error message. |
Okay, we're green! Ready for review. What do y'all think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change makes sense, is well-described, specified, and improves the implementation by moving the LoadError handling closer to the require it protects.
Thanks @botandrose!
Hi there. So provisionally I'm ok with this. I'm trying to find a commit, but maybe you can help. Someone mentioned that with a new-er version of Rails (I can't remember if it was 5.2 or 6.0), database cleaner was no longer required and sort of auto included. But I can't remember the details as it was a long time ago. I remember the thought process here was we were going to remove database cleaner at some point. If I'm wrong that's fine. You may be able to piece things together better for me. I'll try have a dig around. For now can we just hold off. But if everything's ok I'm happy with the approach here, just need to confirm my original thought process was wrong. |
It was in Rails 5.1, and it's not strictly that database_cleaner isn't required. It was more that they made it possible to run tests in a mode where all threads share a database connection, and this mode makes it possible to have transaction-mode cleanup actually work in multi-threading environments like capybara. However, that mode does change the behavior of the app: all threads are sharing one database connection. Rails doesn't have built-in support for any of the other database_cleaner cleanup modes, which you'd still need to use when testing certain kinds of concurrency issues. Fortunately the new test concurrency mode works with database_cleaner's transactional cleanup mode, so even if you have it installed, it can still be used. |
Ok so in essence, adding this new additional permutation won't alter the use case for people who no longer want to use database cleaner in rails 5.1+ ? |
begin | ||
require 'database_cleaner' | ||
rescue LoadError | ||
Cucumber.logger.debug('database_cleaner not present.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably worth hinting that this has checked both gems right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Are you imagining something like "neither database_cleaner v1 or v2 present"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like that yeh
Also when you come back to this, could you rebase with latest master, and add a changelog entry at the top in unreleased |
3314149
to
050995a
Compare
@luke-hill Rebased and changelog updated. Sorry it took so long to get back to this. Last week was crazy IRL. Looks like I missed the v2.1 release train, too. Crap! |
Trying to see if the failure was a genuine timeout or something else (Fairly sure travis just had a moment). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few comments.
CHANGELOG.md
Outdated
|
||
### Changed | ||
|
||
* | ||
|
||
### Fixed | ||
|
||
* | ||
* Database cleaning silently fails when using database_cleaner v2 adapter gems |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this say something like "no longer fails", or have I misunderstood this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I think I see. I was describing the bug, and you would prefer that I describe the bugfix?
begin | ||
require 'database_cleaner' | ||
rescue LoadError | ||
Cucumber.logger.debug('database_cleaner not present.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like that yeh
050995a
to
ccd910c
Compare
@luke-hill I have just pushed the requested changes the changelog message and the warning message. |
Hi @botandrose, Thanks for your making your first contribution to Cucumber, and welcome to the Cucumber committers team! You can now push directly to this repo and all other repos under the cucumber organization! 🍾 In return for this generous offer we hope you will:
On behalf of the Cucumber core team, |
Summary
Hi folks! This PR aims to resolve some incompatibilities with cucumber-rails and the upcoming major v2 release of database_cleaner.
Details
In order to get access to the database_cleaner configuration in a ORM-agnostic way, we first try to require
database_cleaner/core
(which is only available in the database_cleaner v2 family of gems), then fall back to requiringdatabase_cleaner
for folks still on v1, finally falling back to silence if neither is available, since database_cleaner is an optional dependency.Motivation and Context
Last week, we cut beta versions of the next major version of database_cleaner. The main change here is that all of the ORM adapters have been split off into their own gems, e.g. database_cleaner-active_record, database_cleaner-redis, etc. Understanding that the majority of database_cleaner's current users are using it with Rails/ActiveRecord (and this gem, too), we chose to make the database_cleaner v2.0.0 gem a metagem that depends on database_cleaner-active_record, and simply loads that when
require "database_cleaner"
is run. This means that the vast majority of our users won't have to touch a thing to upgrade from database_cleaner v1 to v2.However, not everyone is only using ActiveRecord. There are those who can't get away with just leaving
gem "database_cleaner"
as-is in their Gemfile, and they have a bit more work to do. For example, let's say you're using Rails with Sequel and Redis, and want to upgrade to database_cleaner v2.0.0. No big deal, you just replacegem "database_cleaner"
withgem "database_cleaner-sequel"
andgem "database_cleaner-redis"
and you're good to go. However, in this situation, the current implementation of cucumber-rails' database_cleaner integration will silently fail.The underlying issue is that none of the ORM adapters have a
lib/database_cleaner.rb
file (only the database_cleaner metagem has it, for backwards compatibility with the common case), so therequire "database_cleaner"
call in the "lib/cucumber/rails/hooks/database_cleaner.rb" will silently fail sinceLoadError
is being caught and discarded, the only visible clue being that the database state is now persisting between test cases. Personally, I consider this issue to be a blocker for releasing final v2.0.0 versions of the database_cleaner family of gems.How Has This Been Tested?
The first commit in this PR adds a new cucumber feature that fails, exposing this issue. It does this by simply adding
gem "database_cleaner-active_record"
to the Gemfile, instead ofgem "database_cleaner"
. This was the simplest way to expose the issue without adding a dev dependency on another ORM. This is also a valid and supported way to use database_cleaner with ActiveRecord, BTW.Types of changes
Checklist:
This change should be transparent to consumers of the library.