2

I am following Hartl's Rails Tutorial and using Rails 6. I keep getting persistent errors that seem to pop up at random whenever I run tests - random because the consecutive tests sometimes indicate errors in different areas. These tests are also very very slow - > 30 minutes sometimes. Has anyone encountered this? What could I be doing wrong? And now for the red herring: I am using Win 8.1 :)

The common thing about these errors messages is that they all contain a "RuntimeErroer: database is locked" message. Here's one of them:

ERROR["test_email_validation_should_reject_invalid_addresses", 
#<Minitest::Reporters::Suite:0x000000000c9b29c0 @name="UserTest">, 608.7059665989946]
 test_email_validation_should_reject_invalid_addresses#UserTest (608.71s)
RuntimeError: RuntimeError: database is locked
3
  • 1
    I'm assuming you are using SQLite database? Sometimes Rails Console will lock database, this is common issue for SQLite database. Try running tests with console closed Commented Nov 14, 2019 at 10:54
  • did you checked these answers stackoverflow.com/questions/7154664/… Commented Nov 14, 2019 at 14:07
  • @nuak, I am using SQLite with rails console closed. Commented Nov 16, 2019 at 12:57

4 Answers 4

4

I've been fighting this same error for quite sometime. It actually go so bad it roadblocked me from really moving forward in Hartl's Rails Tutorial.

Edit: Found a much better answer that simply resolves the problem instead of playing with settings I probably don't really understand.

See -> https://stackoverflow.com/a/62730905/10463184

My only contribution, as a windows user, I found that commenting out the entire line in test/test_help.rb...

parallelize(workers: :number_of_processors, with: :threads)

Resolved the issue. Trying the setting suggested at the link resulted in a "UNIXServer is required (LoadError)" error.

Sign up to request clarification or add additional context in comments.

Comments

1

Here's a solution to one of my challenges - the interminablly slow test speed. In the config/database.yml I added (to the test.sqlite part) the following lines:

  database: db/test.sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 3000

The test duration dropped from minutes to mere seconds. Victory!

Alas, the "RuntimeError: database is locked" messages are still there, however.

Comments

0

I found myself in the same situation.

In my case this error happened because the tests run in parallel by default on MiniTest, which means that they also run in parallel in rails. When this happens and there are tests that make transactions on the tests db, the db locks itself causing the error.

The solution that worked for me was setting the attribute "use_transactional_tests" to false in the test class.

You can see the proper usage and an example in the docs.

Comments

0

In case anyone else makes the obvious mistake that I did, be sure to exit out of any rails console sessions in your terminals before trying to delete on your live site or in testing.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.