gpt4 book ai didi

ruby-on-rails - Capybara 和 chrome 驱动程序:SQLite3::BusyException: 数据库被锁定

转载 作者:行者123 更新时间:2023-12-03 18:14:49 25 4
gpt4 key购买 nike

有时我会在运行我的功能规范时使用 chromedriver 进行一些视觉测试等。为此,我只需设置 driver: :chrome在具体规范上。

好像好久没做这个了,今天试了之后,出现如下错误:

SQLite3::BusyException: database is locked

使用默认 JavaScript 驱动程序(即 poltergeist)运行规范时不会发生这种情况。

在 Google 上搜索导致此 solution which shows how to monkey patch active record .不过,这让我感觉很奇怪。为什么之前有效?是线程问题吗?我不喜欢猴子补丁,也许有更好的解决方案。

最佳答案

根据this cucumber rails 中的功能:

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

关于ruby-on-rails - Capybara 和 chrome 驱动程序:SQLite3::BusyException: 数据库被锁定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29387097/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com