-
Notifications
You must be signed in to change notification settings - Fork 206
/
gc_test.rb
102 lines (80 loc) · 2.15 KB
/
gc_test.rb
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/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
super
GC.stress = true
end
def teardown
GC.stress = false
end
def some_method
Array.new(3 * 4)
end
def run_profile
RubyProf::Profile.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
GC.start
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
GC.start
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
GC.start
method_call_infos.each do |call_trees|
refute_empty(call_trees.call_trees)
end
end
def test_hold_onto_measurements
# Run a profile
profile = run_profile
# Get measurement objects
measurements = profile.threads.map(&:methods).flatten.map(&:measurement)
# Free the profiles which frees the measurements
profile = nil
GC.start
measurements.each_with_index 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
GC.start
call_trees.each do |call_tree|
refute_nil(call_tree.source_file)
end
end
end