2015-04-01 88 views
2

偶爾我使用chromedriver運行我的功能規格來做一些視覺測試等。對此,我簡單地設置driver: :chrome在特定的規格。水豚和鉻驅動程序:SQLite3 :: BusyException:數據庫被鎖定

我沒有爲它似乎是一個很長的時間做到這一點,因爲,因爲我今天試了一下,我得到了以下錯誤:

SQLite3::BusyException: database is locked 

使用默認的JavaScript運行規範時,這不會發生司機(這是poltergeist)。

在Google上搜索導致solution which shows how to monkey patch active record。儘管如此,這對我來說感覺很奇怪。爲什麼之前工作?這是一個線程問題嗎?我不喜歡猴子補丁,也許有更好的解決方案。

回答

0

根據this功能黃瓜護欄:

When running a scenario with the @javascript tag, Capybara will fire up a web server in the same process in a separate thread to your cukes. By default, this means ActiveRecord will give it a separate database connection, which in turn means data you put into your database from Cucumber step definitions (e.g. using FactoryGirl) won't be visible to the web server until the database transaction is committed.

So if you use a transaction strategy for cleaning up your database at the end of a scenario, it won't work for javascript scenarios by default.

There are two ways around this. One is to switch to a truncation strategy for javascript scenarios. This is slower, but more reliable.

The alternative is to patch ActiveRecord to share a single database connection between threads. This means you still get the speed benefits of using a transaction to roll back your database, but you run the risk of the two threads stomping on one another as they talk to the database.

Right now, the default behavior is to use truncation, but you can override this by telling cucumber-rails which strategy to use for javascript scenarios.

The deletion strategy can be quicker for situations where truncation causes locks which has been reported by some Oracle users.

從最後一段,你可以通過改變以下行env.rb使用刪除策略:

Cucumber::Rails::Database.javascript_strategy = :truncation 

由:

Cucumber::Rails::Database.javascript_strategy = :deletion 
相關問題