test/test_stackprof.rb in stackprof-0.2.25 vs test/test_stackprof.rb in stackprof-0.2.26

- old
+ new

@@ -2,11 +2,11 @@ require 'stackprof' require 'minitest/autorun' require 'tempfile' require 'pathname' -class StackProfTest < MiniTest::Test +class StackProfTest < Minitest::Test def setup Object.new # warm some caches to avoid flakiness end def test_info @@ -91,10 +91,11 @@ assert_includes frame[:name], "StackProfTest#math" end end def test_walltime + GC.disable profile = StackProf.run(mode: :wall) do idle end frame = profile[:frames].values.first @@ -102,10 +103,12 @@ assert_equal "IO.select", frame[:name] else assert_equal "StackProfTest#idle", frame[:name] end assert_in_delta 200, frame[:samples], 25 + ensure + GC.enable end def test_custom profile_base_line = __LINE__+1 profile = StackProf.run(mode: :custom) do @@ -140,14 +143,17 @@ end after_monotonic = Process.clock_gettime(Process::CLOCK_MONOTONIC, :microsecond) raw = profile[:raw] + raw_lines = profile[:raw_lines] assert_equal 10, raw[-1] assert_equal raw[0] + 2, raw.size + assert_equal 10, raw_lines[-1] # seen 10 times offset = RUBY_VERSION >= '3' ? -3 : -2 + assert_equal 140, raw_lines[offset] # sample caller is on 140 assert_includes profile[:frames][raw[offset]][:name], 'StackProfTest#test_raw' assert_equal 10, profile[:raw_sample_timestamps].size profile[:raw_sample_timestamps].each_cons(2) do |t1, t2| assert_operator t1, :>, before_monotonic @@ -239,11 +245,15 @@ assert gc_frame assert marking_frame assert sweeping_frame - assert_equal gc_frame[:total_samples], profile[:gc_samples] - assert_equal profile[:gc_samples], [gc_frame, marking_frame, sweeping_frame].map{|x| x[:samples] }.inject(:+) + # We can't guarantee a certain number of GCs to run, so just assert + # that it's within some kind of delta + assert_in_delta gc_frame[:total_samples], profile[:gc_samples], 2 + + # Lazy marking / sweeping can cause this math to not add up, so also use a delta + assert_in_delta profile[:gc_samples], [gc_frame, marking_frame, sweeping_frame].map{|x| x[:samples] }.inject(:+), 2 assert_operator profile[:gc_samples], :>, 0 assert_operator profile[:missed_samples], :<=, 25 end