Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

DatabaseCleaner triggering `before` hook while threads are still running

オープン
#683 コメント 2 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
rails, ruby
領域
databases, testing

調査の方向性

このissueにはリポジトリのファイルも失敗するテストも提示されていません。投稿された設定内の RSpec.configure フックと、DatabaseCleaner の before/after ライフサイクルから始めてください。transaction strategy を使い、concurrent-ruby の Future で controller spec を再現してから、クリーンアップのタイミングを Future の完了と比較してください。race が再現され、その原因と解決策または制限が文書化されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Ruby
スター
3k
フォーク
485
PR マージ指標
30日以内にマージされた PR はありません

環境構築

  • Dockerfile または Docker Compose ファイルあり
  • プルリクエストのテンプレートなし
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

DatabaseCleaner/database_cleaner のほかの issue

DatabaseCleaner/database_cleaner の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。