Skip to content

Commit

Permalink
Fix Error in GC Compaction specs
Browse files Browse the repository at this point in the history
Previously if any of the tests that move objects between size pools
failed to move anything, then the call to stats.dig would return `nil`
which would then cause assert_operator to error.

This should be a test Failure, rather than an Error so this commit uses
a default value of 0 if stats.dig fails to find a key.

Also refactor object movement tests to use stats.dig, rather than :[]
  • Loading branch information
eightbitraptor authored and peterzhu2118 committed Jan 3, 2023
1 parent fdac148 commit 0dc989d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions test/ruby/test_gc_compact.rb
Expand Up @@ -323,7 +323,7 @@ def test_moving_arrays_down_size_pools
end
stats = GC.verify_compaction_references(expand_heap: true, toward: :empty)
assert_operator(stats.dig(:moved_down, :T_ARRAY), :>=, ARY_COUNT)
assert_operator(stats.dig(:moved_down, :T_ARRAY) || 0, :>=, ARY_COUNT)
assert(arys) # warning: assigned but unused variable - arys
end;
end
Expand All @@ -345,7 +345,7 @@ def test_moving_arrays_up_size_pools
end
stats = GC.verify_compaction_references(expand_heap: true, toward: :empty)
assert_operator(stats.dig(:moved_up, :T_ARRAY), :>=, ARY_COUNT)
assert_operator(stats.dig(:moved_up, :T_ARRAY) || 0, :>=, ARY_COUNT)
assert(arys) # warning: assigned but unused variable - arys
end;
end
Expand Down Expand Up @@ -375,7 +375,7 @@ def add_ivars
stats = GC.verify_compaction_references(expand_heap: true, toward: :empty)
assert_operator(stats[:moved_up][:T_OBJECT], :>=, OBJ_COUNT)
assert_operator(stats.dig(:moved_up, :T_OBJECT) || 0, :>=, OBJ_COUNT)
end;
end

Expand Down

0 comments on commit 0dc989d

Please sign in to comment.