1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
# frozen_string_literal: true
number_regex = /\d+\.?\d{0,2}/
memory_human_regex = /#{number_regex}[KMGTPEZ]?B/
percent_regex = /#{number_regex}%/
describe "MemoryProf RSpec" do
specify "with default options", :aggregate_failures do
output = run_rspec("memory_prof", env: {"TEST_MEM_PROF" => "test", "TEST_MEM_PROF_COUNT" => "3"})
expect(output).to include("MemoryProf results")
expect(output).to match(/Final RSS: #{memory_human_regex}/)
expect(output).to include("Top 3 groups (by RSS):")
expect(output).to include("Top 3 examples (by RSS):")
end
specify "in RSS mode", :aggregate_failures do
output = run_rspec("memory_prof", env: {"TEST_MEM_PROF" => "rss", "TEST_MEM_PROF_COUNT" => "3"})
expect(output).to include("MemoryProf results")
expect(output).to match(/Final RSS: #{memory_human_regex}/)
expect(output).to include("Top 3 groups (by RSS):")
expect(output).to include("Top 3 examples (by RSS):")
end
if RUBY_ENGINE != "jruby"
specify "in allocations mode", :aggregate_failures do
output = run_rspec("memory_prof", env: {"TEST_MEM_PROF" => "alloc", "TEST_MEM_PROF_COUNT" => "3"})
expect(output).to include("MemoryProf results")
expect(output).to match(/Total allocations: #{number_regex}/)
expect(output).to include("Top 3 groups (by allocations):")
expect(output).to include("Top 3 examples (by allocations):")
expect(output).to match(/Groups Allocations \(\.\/memory_prof_fixture.rb:\d+\) – \+#{number_regex} \(#{percent_regex}\)/)
expect(output).to match(/Examples allocations \(\.\/memory_prof_fixture.rb:\d+\) – \+#{number_regex} \(#{percent_regex}\)/)
expect(output).to match(/allocates 10_000 objects \(\.\/memory_prof_fixture.rb:\d+\) – \+#{number_regex} \(#{percent_regex}\)/)
expect(output).to match(/allocates 1000 objects \(\.\/memory_prof_fixture.rb:\d+\) – \+#{number_regex} \(#{percent_regex}\)/)
expect(output).to match(/allocates 500 objects \(\.\/memory_prof_fixture.rb:\d+\) – \+#{number_regex} \(#{percent_regex}\)/)
end
end
specify "with top_count", :aggregate_failures do
output = run_rspec("memory_prof", env: {"TEST_MEM_PROF" => "rss", "TEST_MEM_PROF_COUNT" => "4"})
expect(output).to include("MemoryProf results")
expect(output).to match(/Final RSS: #{memory_human_regex}/)
expect(output).to include("Top 4 groups (by RSS):")
expect(output).to include("Top 4 examples (by RSS):")
end
if ::GC.respond_to?(:total_time)
specify "in GC mode", :aggregate_failures do
output = run_rspec("memory_prof", env: {"TEST_MEM_PROF" => "gc", "TEST_MEM_PROF_COUNT" => "4"})
expect(output).to include("MemoryProf results")
expect(output).to match(/Total GC time: \d+:\d+.\d+/)
expect(output).to include("Top 4 groups (by GC time):")
expect(output).to include("Top 4 examples (by GC time):")
end
end
end
|