Capybara error ActiveRecord::StatementInvalid: SQLite3::BusyException: database is locked

Rob

I'm testing javascript and I get the following error when I try and submit data to the DB over an ajax form.

ActiveRecord::StatementInvalid:         ActiveRecord::StatementInvalid: SQLite3::BusyException: database is locked: INSERT INTO "check_category_item_keys" ("name", "key_type", "created_at", "updated_at") VALUES (?, ?, ?, ?)

Here is my integration test file

require 'test_helper'

class JavascriptTestingTest < ActionDispatch::IntegrationTest

setup do
    @user = users(:michael)
    @user1 = users(:archer)
    @guide = Guide.find(1)
    @mod_relationship = game_mods_relationships(:mod1)
    @category = Category.find(1)
    Capybara.current_driver = Capybara.javascript_driver # :selenium by default
  end


test "adding keys mod success then fail" do
  log_in_as(@user)
  visit(edit_guide_category_path(@guide, @category))
  itemkeycount = CategoryItemKey.count
  fill_in 'Key name', with: "diablo"
  click_button "Add New Key"  #works fine when this line is removed
end

I'm new to testing JS so I'm guessing there is something more I need to do or something I need to change.

Thomas Walpole

#click_button does not wait for the results of clicking the button to happen since it has no clue what those will be. So in this case #click_button returns immediately, the test ends, and whatever you're using to clean the database between tests (DatabaseCleaner??) starts cleaning the database. During that time the request triggered by click_button starts to get processed but the cleaning thread has already locked the database (or the other way around) so you get an error. The solution is to have a line that waits for a visible side effect of whatever clicking the button does.

fill_in 'Key name', with: "diablo"
click_button "Add New Key"
assert_text "New Key Added!" # or whatever shows up the page

The assert_text will wait (up to a limit) for that text to appear which should mean the database is no longer in use, the test can finish and cleanup can happen. The other thing to watch for is that you're NOT using transaction based testing since that will also cause you all sorts of issues when doing testing with a JS capable driver - see https://github.com/DatabaseCleaner/database_cleaner#what-strategy-is-fastest

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

CapybaraエラーActiveRecord :: StatementInvalid:SQLite3 :: BusyException:データベースがロックされています

分類Dev

'SQLite3::BusyException: database is locked' Exception on upload via carrierwave

分類Dev

ActiveRecord::StatementInvalid PG::UndefinedColumn: ERROR

分類Dev

レーキが中止されました!ActiveRecord :: StatementInvalid:SQLite3 :: ReadOnlyException

分類Dev

ActiveRecord :: StatementInvalid、SQLite3 :: SQLException:そのような列はありません:

分類Dev

rails 4 ActiveRecord :: StatementInvalid

分類Dev

ActiveRecord :: StatementInvalid。SQLite3 :: SQLException:そのようなテーブルはありません

分類Dev

How to check if SQLite database is locked

分類Dev

ActiveRecord :: StatementInvalid(PG :: Error:ERROR:value too long for type charactervariing(255)

分類Dev

ActiveRecord :: StatementInvalid:PG :: InternalError:ERROR:parseerror-無効なジオメトリ

分類Dev

ActiveRecord :: StatementInvalid:SQLite3 :: SQLException:がロールバックできないため、Railsdelayed_jobが機能しません

分類Dev

ActiveRecord :: StatementInvalid PG :: UndefinedColumn:エラー

分類Dev

RegistrationsController#createのActiveRecord :: StatementInvalid

分類Dev

How to insert image into sqlite3 database?

分類Dev

Saving data into sqlite3 database in Swift

分類Dev

Can't INSERT into Sqlite3 database

分類Dev

Google BigQuery "bq show" command returning: sqlite3.OperationalError: database is locked

分類Dev

ActiveRecord :: StatementInvalid:Mysql2 :: Error:インクルードを使用する場合の `where`クエリの不明な列

分類Dev

ActiveRecord :: StatementInvalid(PG :: SyntaxError:ERROR: "。"またはその近くで構文エラーが発生しました。

分類Dev

ActiveRecord :: StatementInvalid:Mysql2 :: Error:名前の変更時にエラーが発生しました

分類Dev

レーキが中止されました!ActiveRecord :: StatementInvalid:SQLite3 :: SQLException:そのようなテーブルはありません:RakeAutomationを機能させる際の問題

分類Dev

ActiveRecord::StatementInvalid (OCIError: ORA-00001: unique constraint (xxxxxxxx) violated

分類Dev

Database is locked - how to fix?

分類Dev

SQLite3 query fails, the error does not

分類Dev

Rails 4 SQLite3::ReadOnlyException: attempt to write a readonly database

分類Dev

Display images from sqlite3 database to a column in QTableWidget with Python

分類Dev

Retrieve column names from sqlite3 database with php

分類Dev

Write to CSV from sqlite3 database in python

分類Dev

Retrieving values from SQLite3 Database for Scotty

Related 関連記事

  1. 1

    CapybaraエラーActiveRecord :: StatementInvalid:SQLite3 :: BusyException:データベースがロックされています

  2. 2

    'SQLite3::BusyException: database is locked' Exception on upload via carrierwave

  3. 3

    ActiveRecord::StatementInvalid PG::UndefinedColumn: ERROR

  4. 4

    レーキが中止されました!ActiveRecord :: StatementInvalid:SQLite3 :: ReadOnlyException

  5. 5

    ActiveRecord :: StatementInvalid、SQLite3 :: SQLException:そのような列はありません:

  6. 6

    rails 4 ActiveRecord :: StatementInvalid

  7. 7

    ActiveRecord :: StatementInvalid。SQLite3 :: SQLException:そのようなテーブルはありません

  8. 8

    How to check if SQLite database is locked

  9. 9

    ActiveRecord :: StatementInvalid(PG :: Error:ERROR:value too long for type charactervariing(255)

  10. 10

    ActiveRecord :: StatementInvalid:PG :: InternalError:ERROR:parseerror-無効なジオメトリ

  11. 11

    ActiveRecord :: StatementInvalid:SQLite3 :: SQLException:がロールバックできないため、Railsdelayed_jobが機能しません

  12. 12

    ActiveRecord :: StatementInvalid PG :: UndefinedColumn:エラー

  13. 13

    RegistrationsController#createのActiveRecord :: StatementInvalid

  14. 14

    How to insert image into sqlite3 database?

  15. 15

    Saving data into sqlite3 database in Swift

  16. 16

    Can't INSERT into Sqlite3 database

  17. 17

    Google BigQuery "bq show" command returning: sqlite3.OperationalError: database is locked

  18. 18

    ActiveRecord :: StatementInvalid:Mysql2 :: Error:インクルードを使用する場合の `where`クエリの不明な列

  19. 19

    ActiveRecord :: StatementInvalid(PG :: SyntaxError:ERROR: "。"またはその近くで構文エラーが発生しました。

  20. 20

    ActiveRecord :: StatementInvalid:Mysql2 :: Error:名前の変更時にエラーが発生しました

  21. 21

    レーキが中止されました!ActiveRecord :: StatementInvalid:SQLite3 :: SQLException:そのようなテーブルはありません:RakeAutomationを機能させる際の問題

  22. 22

    ActiveRecord::StatementInvalid (OCIError: ORA-00001: unique constraint (xxxxxxxx) violated

  23. 23

    Database is locked - how to fix?

  24. 24

    SQLite3 query fails, the error does not

  25. 25

    Rails 4 SQLite3::ReadOnlyException: attempt to write a readonly database

  26. 26

    Display images from sqlite3 database to a column in QTableWidget with Python

  27. 27

    Retrieve column names from sqlite3 database with php

  28. 28

    Write to CSV from sqlite3 database in python

  29. 29

    Retrieving values from SQLite3 Database for Scotty

ホットタグ

アーカイブ