10

For each step of test occurs 2 lines:

WARNING:  there is already a transaction in progress
NOTICE:  there is no transaction in progress

With Spork lines following triples:

NOTICE:  there is no transaction in progress
NOTICE:  there is no transaction in progress
NOTICE:  there is no transaction in progress
WARNING:  there is already a transaction in progress
WARNING:  there is already a transaction in progress
WARNING:  there is already a transaction in progress

I don't know maybe it's important, just warned. GemFile:

group :test do
  gem 'rspec-rails'
  gem 'factory_girl_rails'
  gem 'spork-rails'
  gem 'capybara'
  gem 'database_cleaner'
end

all customized, so there is no need for develop group, and it not helps anyway. this is spec_helper.I found, that it is PostgreSQL feature, but I could not find how to fix it. I will be grateful for the assistance

zishe
  • 10,665
  • 12
  • 64
  • 103
  • 1
    Your link to your `spec_helper.rb` seems to be broken. Which database cleaning strategy are you using? Transaction or truncation? If you're using the former, I might try the latter. – Jason Swett Sep 18 '12 at 17:03
  • Thanks, I moved it to github gist. – zishe Sep 18 '12 at 17:07

2 Answers2

11

In spec_helper.rb

config.use_transactional_examples = false #factoryGirl
config.use_transactional_fixtures = false #fixtures

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

In database.yml

test:
  adapter: postgresql
  encoding: unicode
  host: localhost
  database: myapp_test
  username: my_username
  password:
  allow_concurrency: true
  pool: 5
  min_messages: error

Even if you have set the min_messages option, you may still see console output like the following:

WARNING:  there is already a transaction in progress

Edit the file

/opt/local/var/db/postgresql92/defaultdb/postgresql.conf

and set the following:

client_min_messages = error

Everything should now be running smoothly.

Andreas Lyngstad
  • 4,887
  • 2
  • 36
  • 69
10

In spec_helper.rb, I would try changing this

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

to this

  config.before(:suite) do
    DatabaseCleaner.strategy = :truncation
    DatabaseCleaner.clean_with(:truncation)
  end 
Jason Swett
  • 43,526
  • 67
  • 220
  • 351
  • That might be normal, depending on how many tests you have, and how many objects you're creating, and what you consider extremely slow. – Jason Swett Sep 18 '12 at 17:20
  • But with this warning it works correctly, just my boss doesn't like it, i guess. – zishe Sep 18 '12 at 17:27
  • I would argue that if you're getting warnings and errors, it's not working correctly. How slow is your test suite? 30 seconds? 10 minutes? 4 hours? – Jason Swett Sep 18 '12 at 17:29
  • I prefer to make this notes and warnings instead of waiting anyway. – zishe Sep 18 '12 at 17:32
  • Your test speed seems pretty much normal to me. – Jason Swett Sep 18 '12 at 17:37
  • 1
    @Alder re truncation speed, see http://stackoverflow.com/questions/11419536/postgresql-truncation-speed . Try PostgreSQL 9.2 and see if it's any faster. – Craig Ringer Sep 18 '12 at 23:29
  • I installed it, maybe it's faster, but it's to slow too. – zishe Sep 19 '12 at 06:02
  • 2
    There's seems to be prettier solution — http://stackoverflow.com/a/11068914/535406 – jibiel Dec 15 '12 at 04:57
  • FWIW I have about a thousands tests, the solution linked by @jibiel (set config.use_transactional_examples = false) runs 2.5x faster on my dev machine (mac, postgres, rails 3.0.17) than the solution by swett (set .strategy = truncation) -- specifically 3.5 minutes vs 8 minutes! – jpw Jan 06 '13 at 01:28
  • Hmm, I'd be curious to know whether that method actually utilizes a cleaning strategy at all. If so, the performance benefit would of course make it a better solution, but only if so, because a cleaning strategy is a must-have, in my opinion. – Jason Swett Jan 06 '13 at 02:21
  • Short answer is Yes is still cleans: the test I ran is at the bottom of this blog post http://blog.pardner.com/2013/01/getting-rspec-postgres-databasecleaner-to-play-nicely-together/ which is modeled after http://www.relishapp.com/rspec/rspec-rails/v/2-3/docs/transactional-examples – jpw Jan 06 '13 at 18:30