test/test_stackprof.rb in stackprof-0.2.10 vs test/test_stackprof.rb in stackprof-0.2.11

- old
+ new

@@ -4,11 +4,11 @@ require 'tempfile' class StackProfTest < MiniTest::Test def test_info profile = StackProf.run{} - assert_equal 1.1, profile[:version] + assert_equal 1.2, profile[:version] assert_equal :wall, profile[:mode] assert_equal 1000, profile[:interval] assert_equal 0, profile[:samples] end @@ -16,20 +16,20 @@ assert_equal false, StackProf.running? StackProf.run{ assert_equal true, StackProf.running? } end def test_start_stop_results - assert_equal nil, StackProf.results + assert_nil StackProf.results assert_equal true, StackProf.start assert_equal false, StackProf.start assert_equal true, StackProf.running? - assert_equal nil, StackProf.results + assert_nil StackProf.results assert_equal true, StackProf.stop assert_equal false, StackProf.stop assert_equal false, StackProf.running? assert_kind_of Hash, StackProf.results - assert_equal nil, StackProf.results + assert_nil StackProf.results end def test_object_allocation profile_base_line = __LINE__+1 profile = StackProf.run(mode: :object) do @@ -39,17 +39,16 @@ assert_equal :object, profile[:mode] assert_equal 1, profile[:interval] assert_equal 2, profile[:samples] frame = profile[:frames].values.first - assert_equal "block in StackProfTest#test_object_allocation", frame[:name] + assert_includes frame[:name], "StackProfTest#test_object_allocation" assert_equal 2, frame[:samples] - assert_equal profile_base_line, frame[:line] + assert_includes [profile_base_line - 2, profile_base_line], frame[:line] assert_equal [1, 1], frame[:lines][profile_base_line+1] assert_equal [1, 1], frame[:lines][profile_base_line+2] - - frame = profile[:frames].values[1] + frame = profile[:frames].values[1] if RUBY_VERSION < '2.3' assert_equal [2, 0], frame[:lines][profile_base_line] end def test_object_allocation_interval profile = StackProf.run(mode: :object, interval: 10) do @@ -61,23 +60,23 @@ def test_cputime profile = StackProf.run(mode: :cpu, interval: 500) do math end - assert_operator profile[:samples], :>, 1 + assert_operator profile[:samples], :>=, 1 frame = profile[:frames].values.first - assert_equal "block in StackProfTest#math", frame[:name] + assert_includes frame[:name], "StackProfTest#math" end def test_walltime profile = StackProf.run(mode: :wall) do idle end frame = profile[:frames].values.first assert_equal "StackProfTest#idle", frame[:name] - assert_in_delta 200, frame[:samples], 5 + assert_in_delta 200, frame[:samples], 25 end def test_custom profile_base_line = __LINE__+1 profile = StackProf.run(mode: :custom) do @@ -88,12 +87,12 @@ assert_equal :custom, profile[:mode] assert_equal 10, profile[:samples] frame = profile[:frames].values.first - assert_equal "block (2 levels) in StackProfTest#test_custom", frame[:name] - assert_equal profile_base_line+1, frame[:line] + assert_includes frame[:name], "StackProfTest#test_custom" + assert_includes [profile_base_line-2, profile_base_line+1], frame[:line] assert_equal [10, 10], frame[:lines][profile_base_line+2] end def test_raw profile = StackProf.run(mode: :custom, raw: true) do @@ -103,11 +102,12 @@ end raw = profile[:raw] assert_equal 10, raw[-1] assert_equal raw[0] + 2, raw.size - assert_equal 'block (2 levels) in StackProfTest#test_raw', profile[:frames][raw[-2]][:name] + assert_includes profile[:frames][raw[-2]][:name], 'StackProfTest#test_raw' + assert_equal 10, profile[:raw_timestamp_deltas].size end def test_fork StackProf.run do pid = fork do @@ -118,18 +118,21 @@ assert_equal true, StackProf.running? end end def test_gc - profile = StackProf.run(interval: 100) do + profile = StackProf.run(interval: 100, raw: true) do 5.times do GC.start end end - assert_empty profile[:frames] + raw = profile[:raw] + gc_frame = profile[:frames].values.find{ |f| f[:name] == "(garbage collection)" } + assert gc_frame + assert_equal gc_frame[:samples], profile[:gc_samples] assert_operator profile[:gc_samples], :>, 0 - assert_equal 0, profile[:missed_samples] + assert_operator profile[:missed_samples], :<=, 10 end def test_out tmpfile = Tempfile.new('stackprof-out') ret = StackProf.run(mode: :custom, out: tmpfile) do