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

Transaction is not closed in Rails 4 #198

Closed
daniel-g opened this issue Apr 1, 2013 · 7 comments
Closed

Transaction is not closed in Rails 4 #198

daniel-g opened this issue Apr 1, 2013 · 7 comments

Comments

@daniel-g
Copy link
Contributor

daniel-g commented Apr 1, 2013

Here is my conf:

RSpec.configure do |config|

  def js_example?(example)
    example.metadata[:js] || example.metadata[:selenium]
  end

  config.before(:suite) do
    DatabaseCleaner.clean_with(:truncation)
  end

  config.before(:each) do
    Rails.logger.info '########### Starting transaction'
    DatabaseCleaner.strategy = js_example?(example) ? :truncation : :transaction
    DatabaseCleaner.start
  end

  config.after(:each) do
    Rails.logger.info '########### Ending transaction'
    DatabaseCleaner.clean
  end
end

Here is the test log:

########### Ending transaction
   (0.3ms)  ALTER TABLE "answers" DISABLE TRIGGER ALL;ALTER TABLE "schema_migrations" DISABLE TRIGGER ALL;ALTER TABLE "questions" DISABLE TRIGGER ALL;ALTER TABLE "users" DISABLE TRIGGER ALL
   (6.4ms)  TRUNCATE TABLE "answers", "questions", "users" RESTART IDENTITY CASCADE;
   (0.3ms)  ALTER TABLE "answers" ENABLE TRIGGER ALL;ALTER TABLE "schema_migrations" ENABLE TRIGGER ALL;ALTER TABLE "questions" ENABLE TRIGGER ALL;ALTER TABLE "users" ENABLE TRIGGER ALL
########### Starting transaction
   (0.2ms)  BEGIN
  User Exists (0.7ms)  SELECT 1 AS one FROM "users" WHERE "users"."email" = '[email protected]' LIMIT 1
  SQL (1.5ms)  INSERT INTO "users" ("birthday_date", "country", "created_at", "email", "encrypted_password", "first_name", "last_name", "parent_email_address", "updated_at", "username") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING "id"  [["birthday_date", Fri, 01 Apr 2011], ["country", "Lebanon"], ["created_at", Mon, 01 Apr 2013 16:16:06 UTC +00:00], ["email", "[email protected]"], ["encrypted_password", "$2a$04$FZ5uHMwRSlfJD0hFdauD.OQygT10rVT6vhJZ0FiKhL1XdvgzUOYjy"], ["first_name", "Theodora Block I"], ["last_name", "Williamson"], ["parent_email_address", "[email protected]"], ["updated_at", Mon, 01 Apr 2013 16:16:06 UTC +00:00], ["username", "sally_gulgowski"]]
########### Ending transaction
########### Starting transaction
   (0.2ms)  BEGIN
  User Exists (1.0ms)  SELECT 1 AS one FROM "users" WHERE "users"."email" = '[email protected]' LIMIT 1

As you can see in the log, after it truncates, it opens a new transaction to insert, but then it is not closed. The test holds there.

@bmabey
Copy link
Contributor

bmabey commented Apr 1, 2013

What version are you using? Try the release candidate if you haven't already.

@daniel-g
Copy link
Contributor Author

daniel-g commented Apr 1, 2013

gem 'rails', '~> 4.0.0.beta1'
gem 'database_cleaner', git: '[email protected]:bmabey/database_cleaner.git'

I updated the gem revision 2 hours ago, I thought the last commit about the connection had already solved the issue, but it didn't.

@bobbytables
Copy link

I think this is actually a rails issue as I was experiencing it without db cleaner.

@daniel-g
Copy link
Contributor Author

daniel-g commented Apr 8, 2013

Do you know if there is already an issue there?

@bmabey bmabey closed this as completed Apr 8, 2013
@zealot128
Copy link

Just for googlers to save some hours of debugging:

We had a similar database deadlock problem together with Capybara/Poltergeist.
We used database-cleaner with around filters:

config.around(:each) do |example|
    DatabaseCleaner.strategy = example.metadata[:js] ? :truncation : :transaction
    DatabaseCleaner.start
    example.run
    DatabaseCleaner.clean   
end

switching to ordinary before/after fixed our deadlock in our feature specs.

@schnittchen
Copy link

@zealot128 your solution does not work for me, as I then run into #273

@claptimes5
Copy link
Contributor

I believe this is still and issue and should be reopened. I had issue #273 as well and was able to hack a solution by rolling back open transactions before deleting or truncating my tables

claptimes5@347b74b

This should be taken care of in the Transaction clean method, but I haven't had time yet to determine a solution.

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

No branches or pull requests

6 participants