| 12
 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
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 
 | #!/usr/bin/env ruby
# encoding: UTF-8
require File.expand_path('../test_helper', __FILE__)
Minitest::Test.i_suck_and_my_tests_are_order_dependent!
class GcTest < TestCase
  def setup
    GC.stress = true
  end
  def teardown
    GC.stress = false
  end
  def some_method
    Array.new(3 * 4)
  end
  def run_profile
    RubyProf.profile do
      self.some_method
    end
  end
  def test_hold_onto_thread
    threads = 5.times.reduce(Array.new) do |array, i|
      array.concat(run_profile.threads)
      array
    end
    threads.each do |thread|
      refute_nil(thread.id)
    end
  end
  def test_hold_onto_method
    methods = 5.times.reduce(Array.new) do |array, i|
      profile = run_profile
      array.concat(profile.threads.map(&:methods).flatten)
      array
    end
    methods.each do |method|
      refute_nil(method.method_name)
    end
  end
  def test_hold_onto_call_trees
    method_call_infos = 5.times.reduce(Array.new) do |array, i|
      profile = run_profile
      call_trees = profile.threads.map(&:methods).flatten.map(&:call_trees).flatten
      array.concat(call_trees)
      array
    end
    method_call_infos.each do |call_trees|
      refute_empty(call_trees.call_trees)
    end
  end
  def test_hold_onto_measurements
    measurements = 5.times.reduce(Array.new) do |array, i|
      profile = run_profile
      measurements = profile.threads.map(&:methods).flatten.map(&:measurement)
      array.concat(measurements)
      array
    end
    measurements.each do |measurement|
      error = assert_raises(RuntimeError) do
        measurement.total_time
      end
      assert_match(/RubyProf::Measurement instance has already been freed/, error.message)
    end
    assert(true)
  end
  def test_hold_onto_root_call_tree
    call_trees = 5.times.reduce(Array.new) do |array, i|
      array.concat(run_profile.threads.map(&:call_tree))
      array
    end
    call_trees.each do |call_tree|
      refute_nil(call_tree.source_file)
    end
  end
end
 |