File: memory_prof_minitest_spec.rb

package info (click to toggle)
ruby-test-prof 1.6.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,448 kB
  • sloc: ruby: 13,093; sh: 4; makefile: 4
file content (63 lines) | stat: -rw-r--r-- 3,552 bytes parent folder | download
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
# frozen_string_literal: true

number_regex = /\d+\.?\d{0,2}/
memory_human_regex = /#{number_regex}[KMGTPEZ]?B/
percent_regex = /#{number_regex}%/

describe "MemoryProf Minitest" do
  specify "with default options", :aggregate_failures do
    output = run_minitest("memory_prof", env: {"TEST_MEM_PROF" => "test"})

    expect(output).to include("MemoryProf results")
    expect(output).to match(/Final RSS: #{memory_human_regex}/)

    expect(output).to include("Top 5 examples (by RSS):")

    expect(output).to match(/allocates 10_000 objects \(\.\/memory_prof_fixture.rb:\d+\) – \+#{memory_human_regex} \(#{percent_regex}\)/)
    expect(output).to match(/allocates 1000 objects \(\.\/memory_prof_fixture.rb:\d+\) – \+#{memory_human_regex} \(#{percent_regex}\)/)
    expect(output).to match(/allocates 500 objects \(\.\/memory_prof_fixture.rb:\d+\) – \+#{memory_human_regex} \(#{percent_regex}\)/)
    expect(output).to match(/allocates 100 objects \(\.\/memory_prof_fixture.rb:\d+\) – \+#{memory_human_regex} \(#{percent_regex}\)/)
    expect(output).to match(/allocates nothing \(\.\/memory_prof_fixture.rb:\d+\) – \+#{memory_human_regex} \(#{percent_regex}\)/)
  end

  specify "in RSS mode", :aggregate_failures do
    output = run_minitest("memory_prof", env: {"TEST_MEM_PROF" => "rss"})

    expect(output).to include("MemoryProf results")
    expect(output).to match(/Final RSS: #{memory_human_regex}/)

    expect(output).to include("Top 5 examples (by RSS):")

    expect(output).to match(/allocates 10_000 objects \(\.\/memory_prof_fixture.rb:\d+\) – \+#{memory_human_regex} \(#{percent_regex}\)/)
    expect(output).to match(/allocates 1000 objects \(\.\/memory_prof_fixture.rb:\d+\) – \+#{memory_human_regex} \(#{percent_regex}\)/)
    expect(output).to match(/allocates 500 objects \(\.\/memory_prof_fixture.rb:\d+\) – \+#{memory_human_regex} \(#{percent_regex}\)/)
    expect(output).to match(/allocates 100 objects \(\.\/memory_prof_fixture.rb:\d+\) – \+#{memory_human_regex} \(#{percent_regex}\)/)
    expect(output).to match(/allocates nothing \(\.\/memory_prof_fixture.rb:\d+\) – \+#{memory_human_regex} \(#{percent_regex}\)/)
  end

  if RUBY_ENGINE != "jruby"
    specify "in allocations mode", :aggregate_failures do
      output = run_minitest("memory_prof", env: {"TEST_MEM_PROF" => "alloc"})

      expect(output).to include("MemoryProf results")
      expect(output).to match(/Total allocations: #{number_regex}/)

      expect(output).to include("Top 5 examples (by allocations):")

      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}\)/)
      expect(output).to match(/allocates 100 objects \(\.\/memory_prof_fixture.rb:\d+\) – \+#{number_regex} \(#{percent_regex}\)/)
      expect(output).to match(/allocates nothing \(\.\/memory_prof_fixture.rb:\d+\) – \+#{number_regex} \(#{percent_regex}\)/)
    end
  end

  specify "with top_count", :aggregate_failures do
    output = run_minitest("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 examples (by RSS):")
  end
end