Skip to content

Commit

Permalink
check GC.enable'd status
Browse files Browse the repository at this point in the history
Check GC.enable'd status before and after test execution.

Write this checker in gc_checker.rb, it was renamed from
gc_compact_checker.rb.
  • Loading branch information
ko1 committed Aug 5, 2021
1 parent 405644f commit 228b3e4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
36 changes: 36 additions & 0 deletions tool/lib/gc_checker.rb
@@ -0,0 +1,36 @@
# frozen_string_literal: true

module GCDisabledChecker
def before_setup
if @__gc_disabled__ = GC.enable # return true if GC is disabled
GC.disable
end

super
end

def after_teardown
super

disabled = GC.enable
GC.disable if @__gc_disabled__

if @__gc_disabled__ != disabled
label = {
true => 'disabled',
false => 'enabled',
}
raise "GC was #{label[@__gc_disabled__]}, but is #{label[disabled]} after the test."
end
end
end

module GCCompactChecker
def after_teardown
super
GC.compact
end
end

Test::Unit::TestCase.include GCDisabledChecker
Test::Unit::TestCase.include GCCompactChecker if ENV['RUBY_TEST_GC_COMPACT']
10 changes: 0 additions & 10 deletions tool/lib/gc_compact_checker.rb

This file was deleted.

2 changes: 1 addition & 1 deletion tool/lib/test/unit/parallel.rb
Expand Up @@ -6,7 +6,7 @@
require "tracepointchecker"
require "zombie_hunter"
require "iseq_loader_checker"
require "gc_compact_checker"
require "gc_checker"

module Test
module Unit
Expand Down
2 changes: 1 addition & 1 deletion tool/test/runner.rb
Expand Up @@ -9,7 +9,7 @@
require "tracepointchecker"
require "zombie_hunter"
require "iseq_loader_checker"
require "gc_compact_checker"
require "gc_checker"
require_relative "../test-coverage.rb" if ENV.key?('COVERAGE')

case $0
Expand Down

0 comments on commit 228b3e4

Please sign in to comment.