Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

DatabaseCleaner triggering `before` hook while threads are still running

Đang mở
#683 2 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
rails, ruby
Lĩnh vực
databases, testing

Hướng nghiên cứu

Issue không cung cấp tệp nào của repository hoặc test bị lỗi; hãy bắt đầu với các hook RSpec.configure trong config được đăng và vòng đời before/after của DatabaseCleaner. Tái hiện controller spec bằng Future của concurrent-ruby với transaction strategy, sau đó so sánh thời điểm cleanup với thời điểm Future hoàn tất. Được xem là hoàn thành khi race được tái hiện và nguyên nhân cùng cách giải quyết hoặc giới hạn của nó được ghi lại.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

This one is hard to reproduce, might not have anything to do with DC but I tracked the issue down to the DC configuration/behavior.

I have a code that runs a couple of operations on threads, using concurrent-ruby's Future. It goes along these lines:

Rails.application.executor.wrap do
  future = Concurrent::Future.execute do
    Rails.application.executor.wrap(executor: executor) do
      operation_that_finds_a_user_on_db
    end
  end

 values = ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
    future.value!
  end
end

when I'm running controller specs that invoke this part of code, they fail and the exception is that there are no users on the database anymore. I tracked the issue down to DC doing a clean-up.

It looks like DC is running even though Futures are not finished yet. I can't say that this is an issue with DC but I figure that this could be a starting point

Here is my whole config file

RSpec.configure do |config|
  DatabaseCleaner.allow_remote_database_url = true if Rails.env.test?

  config.before(:suite) do
    DatabaseCleaner.clean_with(:deletion)
  end

  config.before do
    DatabaseCleaner.strategy = :transaction
  end

  config.before(:each, js: true) do
    DatabaseCleaner.strategy = :deletion
  end

  config.before do
    DatabaseCleaner.start
  end

  config.after do
    DatabaseCleaner.clean
  end
end

Does this make any sense?

Edit: I noticed that changing the strategy from transaction to deletion or truncation worked but the tests got SO much slower that it's not even an option

Ngôn ngữ chính
Ruby
Star
3k
Fork
485
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

  • Có Dockerfile hoặc tệp Docker Compose
  • Không có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của DatabaseCleaner/database_cleaner

Tất cả issue của DatabaseCleaner/database_cleaner

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.