最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ruby on rails - Database timeout when running RSpecCapybara with javascript driver - Stack Overflow

programmeradmin0浏览0评论

I'm trying to get some RSpec examples working with Capybara using the javascript driver (w/ Webkit or Poltergeist) but there's a locking issue with the database when updating a table. Here's part of the example in question:

  scenario 'by changing the contract attributes', js: true do
    login_as @admin, scope: :user

    contract = Contract.create(number: '123',
                               start_at: Date.today,
                               end_at: Date.today + 1.month)

    visit "/contracts/#{contract.id}/edit"

I'm using Devise and the Warden::Test::Helpers to login.

Running RSpec takes a while and all I get:

 Failure/Error: visit "/contracts/#{contract.id}/edit"
 Capybara::Driver::Webkit::WebkitInvalidResponseError:
   Unable to load URL: http://127.0.0.1:46520/contracts/1/edit

The log is showing that there's a database locking issue:

Started GET "/contracts/1/edit" for 127.0.0.1 at 2012-06-01 12:10:26 -0400
   (0.2ms)  BEGIN
   (51083.3ms)  UPDATE `users` SET `last_sign_in_at` = '2012-06-01 16:10:26', `current_sign_in_at` = '2012-06-01 16:10:26', `last_sign_in_ip` = '127.0.0.1', `current_sign_in_ip` = '127.0.0.1', `sign_in_count` = 1, `updated_at` = '2012-06-01 16:10:26' WHERE `users`.`id` = 1
Mysql2::Error: Lock wait timeout exceeded; try restarting transaction: UPDATE `users` SET `last_sign_in_at` = '2012-06-01 16:10:26', `current_sign_in_at` = '2012-06-01 16:10:26', `last_sign_in_ip` = '127.0.0.1', `current_sign_in_ip` = '127.0.0.1', `sign_in_count` = 1, `updated_at` = '2012-06-01 16:10:26' WHERE `users`.`id` = 1
   (0.8ms)  ROLLBACK

I've tried lots of things (that question seemed to closest to an actual solution: Capybara with :js => true causes test to fail) but nothing worked, even getting rid of DatabaseCleaner. Is there anything else I could try?

Edit: Here's the spec_helper.rb file as requested:

I'm trying to get some RSpec examples working with Capybara using the javascript driver (w/ Webkit or Poltergeist) but there's a locking issue with the database when updating a table. Here's part of the example in question:

  scenario 'by changing the contract attributes', js: true do
    login_as @admin, scope: :user

    contract = Contract.create(number: '123',
                               start_at: Date.today,
                               end_at: Date.today + 1.month)

    visit "/contracts/#{contract.id}/edit"

I'm using Devise and the Warden::Test::Helpers to login.

Running RSpec takes a while and all I get:

 Failure/Error: visit "/contracts/#{contract.id}/edit"
 Capybara::Driver::Webkit::WebkitInvalidResponseError:
   Unable to load URL: http://127.0.0.1:46520/contracts/1/edit

The log is showing that there's a database locking issue:

Started GET "/contracts/1/edit" for 127.0.0.1 at 2012-06-01 12:10:26 -0400
   (0.2ms)  BEGIN
   (51083.3ms)  UPDATE `users` SET `last_sign_in_at` = '2012-06-01 16:10:26', `current_sign_in_at` = '2012-06-01 16:10:26', `last_sign_in_ip` = '127.0.0.1', `current_sign_in_ip` = '127.0.0.1', `sign_in_count` = 1, `updated_at` = '2012-06-01 16:10:26' WHERE `users`.`id` = 1
Mysql2::Error: Lock wait timeout exceeded; try restarting transaction: UPDATE `users` SET `last_sign_in_at` = '2012-06-01 16:10:26', `current_sign_in_at` = '2012-06-01 16:10:26', `last_sign_in_ip` = '127.0.0.1', `current_sign_in_ip` = '127.0.0.1', `sign_in_count` = 1, `updated_at` = '2012-06-01 16:10:26' WHERE `users`.`id` = 1
   (0.8ms)  ROLLBACK

I've tried lots of things (that question seemed to closest to an actual solution: Capybara with :js => true causes test to fail) but nothing worked, even getting rid of DatabaseCleaner. Is there anything else I could try?

Edit: Here's the spec_helper.rb file as requested: https://gist.github./2855631

Share Improve this question edited May 23, 2017 at 11:53 CommunityBot 11 silver badge asked Jun 1, 2012 at 17:06 Nicolas BuduroiNicolas Buduroi 3,5841 gold badge30 silver badges30 bronze badges 2
  • Can you post your spec_helper file? – DVG Commented Jun 1, 2012 at 20:56
  • @DVG I've edited my question with a link to gist. – Nicolas Buduroi Commented Jun 1, 2012 at 23:01
Add a ment  | 

2 Answers 2

Reset to default 5

It's almost certainly

config.use_transactional_fixtures = true

Which is trying to run your example inside of a transaction, for the purpose of having clean data. Since you're using Database Cleaner, you already have this feature, so set this to false and you should be good to go.

https://www.relishapp./rspec/rspec-rails/docs/transactions

For me the solution was just the opposite :)

I have set it to false:

config.use_transactional_fixtures = false

And it all worked. With true it wasn't working just as before.

发布评论

评论列表(0)

  1. 暂无评论