[英]benchmark-rspec is stuck without any notifications
Im trying to test memory allocation.我正在尝试测试内存分配。 And choose for it
rspec-benchmark
gem.并为它选择
rspec-benchmark
gem。 But found some strange behaviour I don't understand.但是发现了一些我不明白的奇怪行为。 To reproduce it we can write spec like this:
为了重现它,我们可以这样编写规范:
require 'rails_helper'
describe ApplicationsManagement::Export do
let(:applications_collection) { create_list(:application, 1 ) }
describe '#call' do
it 'comsumpts not more 1 MB' do
i = 0
expect { applications_collection.each { |app| puts i += 1 } }.to perform_allocation(1_048_576).bytes
end
end
end
When we run spec we have to wait few minutes!!当我们运行规范时,我们必须等待几分钟!!
ApplicationsManagement::Export
#call
1
comsumpts not more 1 MB (FAILED - 1)
Failures:
1) ApplicationsManagement::Export#call comsumpts not more 1 MB
Failure/Error: expect { applications_collection.each { |app| puts i += 1 } }.to perform_allocation(1_048_576).bytes
expected block to perform allocation of 1048576 bytes, but allocated 10694166 bytes
# ./spec/services/applications_management/export_spec.rb:16:in `block (3 levels) in <top (required)>'
# ./spec/rails_helper.rb:55:in `block (3 levels) in <top (required)>'
# ./spec/rails_helper.rb:54:in `block (2 levels) in <top (required)>'
Finished in 4 minutes 8.5 seconds (files took 21.99 seconds to load)
1 example, 1 failure
To be honest, it was the first time I see the output, because I didn't wait never.老实说,这是我第一次看到输出,因为我从来没有等过。 Anyway its too long time for only one application creating and allocating 1 Mb memory.
无论如何,只有一个应用程序创建和分配 1 Mb 内存的时间太长了。 What am I doing wrong, why this spec is running so long?
我做错了什么,为什么这个规范运行这么久?
spec/rails_helper.rb规格/rails_helper.rb
require 'rspec-benchmark'
RSpec.configure do |config|
config.include RSpec::Benchmark::Matchers
...
PS: PS:
rails 4.2.9
rspec (3.5.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-benchmark (0.5.1)
benchmark-malloc (~> 0.1.0)
benchmark-perf (~> 0.5.0)
benchmark-trend (~> 0.3.0)
rspec (>= 3.0.0, < 4.0.0)
rspec-core (3.5.4)
rspec-support (~> 3.5.0)
Thank you so much!非常感谢!
I've found that if I pass FactoryBot.create(...)
to the expect
block, then I got the stuck behaviour.我发现如果我将
FactoryBot.create(...)
传递给expect
块,那么我就会遇到卡住的行为。 But if one row before I have initialized the objects.但是如果在我初始化对象之前的一行。 Then example working as expected.
然后示例按预期工作。
require 'rails_helper'
describe ApplicationsManagement::Export do
let(:applications_collection) { create_list(:application, 1) }
describe '#call' do
it 'comsumpts not more 1 MB' do
applications_collection
i = 0
expect { applications_collection.each { |app| puts i += 1 } }.to perform_allocation(1_048_576).bytes
end
end
end
ApplicationsManagement::Export
#call
1
comsumpts not more 1 MB
Finished in 1.17 seconds (files took 21.71 seconds to load)
1 example, 0 failures
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.