test/test_stackprof.rb in stackprof-0.2.13 vs test/test_stackprof.rb in stackprof-0.2.14

- old
+ new

@@ -107,10 +107,40 @@ assert_equal raw[0] + 2, raw.size assert_includes profile[:frames][raw[-2]][:name], 'StackProfTest#test_raw' assert_equal 10, profile[:raw_timestamp_deltas].size end + def test_metadata + metadata = { + path: '/foo/bar', + revision: '5c0b01f1522ae8c194510977ae29377296dd236b', + } + profile = StackProf.run(mode: :cpu, metadata: metadata) do + math + end + + assert_equal metadata, profile[:metadata] + end + + def test_empty_metadata + profile = StackProf.run(mode: :cpu) do + math + end + + assert_equal({}, profile[:metadata]) + end + + def test_raises_if_metadata_is_not_a_hash + exception = assert_raises ArgumentError do + StackProf.run(mode: :cpu, metadata: 'foobar') do + math + end + end + + assert_equal 'metadata should be a hash', exception.message + end + def test_fork StackProf.run do pid = fork do exit! StackProf.running?? 1 : 0 end @@ -148,13 +178,21 @@ end end raw = profile[:raw] gc_frame = profile[:frames].values.find{ |f| f[:name] == "(garbage collection)" } + marking_frame = profile[:frames].values.find{ |f| f[:name] == "(marking)" } + sweeping_frame = profile[:frames].values.find{ |f| f[:name] == "(sweeping)" } + assert gc_frame - assert_equal gc_frame[:samples], profile[:gc_samples] + 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(:+) + assert_operator profile[:gc_samples], :>, 0 - assert_operator profile[:missed_samples], :<=, 10 + assert_operator profile[:missed_samples], :<=, 25 end def test_out tmpfile = Tempfile.new('stackprof-out') ret = StackProf.run(mode: :custom, out: tmpfile) do