Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix occasional "database is locked" errors while loading sample data #4648

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions sample/lib/spree_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ class Engine < Rails::Engine

# Needs to be here so we can access it inside the tests
def self.load_samples
original_active_job_adapter = ActiveJob::Base.queue_adapter

# SQLite doesn't support full-concurrency and often fails with
# "SQLite3::BusyException: database is locked" when ActiveJob uses the default
# threaded `:async` adapter. ActiveJob is used by ActiveStorage to analyze uploaded
# images for metadata.
if ActiveRecord::Base.connection.adapter_name == "SQLite"
ActiveJob::Base.queue_adapter = :inline
end

Spree::Sample.load_sample("payment_methods")
Spree::Sample.load_sample("tax_categories")
Spree::Sample.load_sample("tax_rates")
Expand All @@ -27,6 +37,8 @@ def self.load_samples
Spree::Sample.load_sample("orders")
Spree::Sample.load_sample("payments")
Spree::Sample.load_sample("reimbursements")
ensure
ActiveJob::Base.queue_adapter = original_active_job_adapter
end
end
end