【发布时间】:2019-05-20 15:50:42
【问题描述】:
在运行 parallel_rspec 规范时随机失败,控制器任何解决方案。
在 Gemfile 中
group :development, :test do
gem 'parallel_tests'
end
我的 Spec 执行是这样的
name@root:/project# parallel_rspec spec/controllers/
4 processes for 21 specs, ~ 5 specs per process
Randomized with seed 3503
Randomized with seed 41377
0/62 |> | ETA: ??:??:??
Randomized with seed 43603
0/50 |> | ETA: ??:??:??
Randomized with seed 61169
3/62 |==> | ETA: 00:08:03
1) Admin::ReportingsController when signed-in non-admin GET #instance_reports redirects to root_url
Failure/Error: expect( response ).to redirect_to root_url
Expected response to be a redirect to <http://xxx/> but was a redirect to <http://yyyy>.
Expected "http://xxxx/" to be === "http://xxxx/code".
# ./spec/support/functions.rb:12:in `expect_root_redirect'
# ./spec/controllers/admin/reportings_controller_spec.rb:25:in `block (4 levels) in <top (required)>'
# ./spec/support/factory_bot.rb:18:in `block (3 levels) in <top (required)>'
# /usr/local/bundle/gems/database_cleaner-1.7.0/lib/database_cleaner/generic/base.rb:16:in `cleaning'
# /usr/local/bundle/gems/database_cleaner-1.7.0/lib/database_cleaner/base.rb:100:in `cleaning'
# /usr/local/bundle/gems/database_cleaner-1.7.0/lib/database_cleaner/configuration.rb:86:in `block (2 levels) in cleaning'
# /usr/local/bundle/gems/database_cleaner-1.7.0/lib/database_cleaner/configuration.rb:87:in `cleaning'
# ./spec/support/factory_bot.rb:17:in `block (2 levels) in <top (required)>'
像这样随机失败。
如果我们使用以下命令运行,它可以正常工作。
rspec spec/controllers
注意:
- 执行时连接单个 DB。
- 除了控制器一切正常。
- 大部分像json相关的条件都失败了。
【问题讨论】:
-
您使用多个数据库吗?每个线程一个?
-
你希望别人如何回答这个问题?我们需要能够重现问题(或至少看到足够多的代码来发现潜在错误)才能给出有意义的响应。
-
请找到上面的输入,除此之外还需要什么!
-
使用 1 个文件运行它工作正常,但不止一个它的填充像 ActiveRecord::Deadlocked ,JSON 错误,响应代码不匹配 等.. 但是模型和其他测试用例使用 parallel_rspec 命令可以正常工作(单个文件和文件夹也是如此)如果我们使用以下命令运行它可以工作 > parallel_rspec -n 1 -t rspec规范/控制器,但单独的多进程不适用于控制器。
-
一种可能是您的测试有副作用,请尝试运行
bundle exec rspec --seed 61169或将61169替换为任何失败的种子编号。 Rspec 将尝试找到导致套件失败的最小集合,有可能一个测试设置了一个环境变量,而另一个测试意外使用了它。
标签: ruby-on-rails ruby testing rspec