Module: HeapScope::Minitest
- Defined in:
- lib/heapscope/minitest.rb
Instance Method Summary collapse
- #assert_heapscope_budget(budget, **opts) ⇒ Object
- #assert_heapscope_bytes_under(limit, force_gc: true, &block) ⇒ Object
- #assert_heapscope_healthy(force_gc: true, &block) ⇒ Object
- #assert_heapscope_no_code(code, force_gc: true, &block) ⇒ Object
- #assert_heapscope_retained_under(limit, force_gc: true, klass: nil, &block) ⇒ Object
Instance Method Details
#assert_heapscope_budget(budget, **opts) ⇒ Object
25 26 27 28 29 |
# File 'lib/heapscope/minitest.rb', line 25 def assert_heapscope_budget(budget, **opts, &) report = HeapScope.check_budget(budget: budget, **opts, &) assert report.passed_budget?, report.budget_result[:violations].join("\n") report end |
#assert_heapscope_bytes_under(limit, force_gc: true, &block) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/heapscope/minitest.rb', line 17 def assert_heapscope_bytes_under(limit, force_gc: true, &block) report = HeapScope.measure(force_gc: force_gc, &block) actual = report.diff&.heap_bytes_estimate_delta.to_i assert actual < limit, "expected retained bytes < #{limit}, got #{actual}" report end |
#assert_heapscope_healthy(force_gc: true, &block) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/heapscope/minitest.rb', line 31 def assert_heapscope_healthy(force_gc: true, &block) report = HeapScope.measure(force_gc: force_gc, &block) assert report.healthy? || report.findings.none? { |f| f.severity == :high }, "expected healthy profile, got #{report.findings.map(&:code)}" report end |
#assert_heapscope_no_code(code, force_gc: true, &block) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/heapscope/minitest.rb', line 38 def assert_heapscope_no_code(code, force_gc: true, &block) report = HeapScope.measure(force_gc: force_gc, &block) refute report.findings.any? { |f| f.code == code }, "expected no #{code}, got #{report.findings.map(&:code)}" report end |
#assert_heapscope_retained_under(limit, force_gc: true, klass: nil, &block) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/heapscope/minitest.rb', line 8 def assert_heapscope_retained_under(limit, force_gc: true, klass: nil, &block) report = HeapScope.measure(force_gc: force_gc, &block) actual = klass ? report.retained_count_for(klass) : report.diff&.surviving_estimate.to_i assert actual < limit, "expected retained objects < #{limit}, got #{actual}. " \ "Suspects: #{report.suspects.first(5).map { |s| s[:name] }.join(', ')}" report end |