Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
102 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,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 | ||
#!/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 |