test/test_stackprof.rb in stackprof-0.2.16 vs test/test_stackprof.rb in stackprof-0.2.17
- old
+ new
@@ -37,20 +37,34 @@
Object.new
Object.new
end
assert_equal :object, profile[:mode]
assert_equal 1, profile[:interval]
- assert_equal 2, profile[:samples]
+ if RUBY_VERSION >= '3'
+ assert_equal 4, profile[:samples]
+ else
+ assert_equal 2, profile[:samples]
+ end
frame = profile[:frames].values.first
assert_includes frame[:name], "StackProfTest#test_object_allocation"
assert_equal 2, frame[:samples]
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]
+ if RUBY_VERSION >= '3'
+ assert_equal [2, 1], frame[:lines][profile_base_line+1]
+ assert_equal [2, 1], frame[:lines][profile_base_line+2]
+ else
+ assert_equal [1, 1], frame[:lines][profile_base_line+1]
+ assert_equal [1, 1], frame[:lines][profile_base_line+2]
+ end
frame = profile[:frames].values[1] if RUBY_VERSION < '2.3'
- assert_equal [2, 0], frame[:lines][profile_base_line]
+
+ if RUBY_VERSION >= '3'
+ assert_equal [4, 0], frame[:lines][profile_base_line]
+ else
+ assert_equal [2, 0], frame[:lines][profile_base_line]
+ end
end
def test_object_allocation_interval
profile = StackProf.run(mode: :object, interval: 10) do
100.times { Object.new }
@@ -62,21 +76,26 @@
profile = StackProf.run(mode: :cpu, interval: 500) do
math
end
assert_operator profile[:samples], :>=, 1
- frame = profile[:frames].values.first
+ offset = RUBY_VERSION >= '3' ? 1 : 0
+ frame = profile[:frames].values[offset]
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]
+ if RUBY_VERSION >= '3'
+ assert_equal "IO.select", frame[:name]
+ else
+ assert_equal "StackProfTest#idle", frame[:name]
+ end
assert_in_delta 200, frame[:samples], 25
end
def test_custom
profile_base_line = __LINE__+1
@@ -87,14 +106,20 @@
end
assert_equal :custom, profile[:mode]
assert_equal 10, profile[:samples]
- frame = profile[:frames].values.first
+ offset = RUBY_VERSION >= '3' ? 1 : 0
+ frame = profile[:frames].values[offset]
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]
+
+ if RUBY_VERSION >= '3'
+ assert_equal [10, 0], frame[:lines][profile_base_line+2]
+ else
+ assert_equal [10, 10], frame[:lines][profile_base_line+2]
+ end
end
def test_raw
profile = StackProf.run(mode: :custom, raw: true) do
10.times do
@@ -103,10 +128,12 @@
end
raw = profile[:raw]
assert_equal 10, raw[-1]
assert_equal raw[0] + 2, raw.size
- assert_includes profile[:frames][raw[-2]][:name], 'StackProfTest#test_raw'
+
+ offset = RUBY_VERSION >= '3' ? -3 : -2
+ assert_includes profile[:frames][raw[offset]][:name], 'StackProfTest#test_raw'
assert_equal 10, profile[:raw_timestamp_deltas].size
end
def test_metadata
metadata = {