Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

DatabaseCleaner triggering `before` hook while threads are still running

未关闭
#683 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
rails, ruby
领域
databases, testing

调研方向

该 issue 没有提供 repository 文件或失败的测试;请从已发布 config 中的 RSpec.configure hooks 以及 DatabaseCleaner 的 before/after 生命周期开始。使用 concurrent-ruby 的 Future 和 transaction strategy 重现 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
派生
484
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

DatabaseCleaner/database_cleaner 的其他 Issue

查看 DatabaseCleaner/database_cleaner 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。