Skip to content

Commit

Permalink
Add --gc-stress option
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Sep 8, 2023
1 parent 16c1b7a commit bdd1668
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/test/unit/autorunner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def need_auto_run=(need)
attr_accessor :color_scheme, :listeners
attr_writer :stop_on_failure
attr_writer :debug_on_failure
attr_writer :gc_stress
attr_writer :runner, :collector

def initialize(standalone)
Expand All @@ -161,6 +162,7 @@ def initialize(standalone)
@listeners = []
@stop_on_failure = false
@debug_on_failure = false
@gc_stress = false
config_file = "test-unit.yml"
if File.exist?(config_file)
load_config(config_file)
Expand Down Expand Up @@ -393,6 +395,12 @@ def options
AssertionFailedError.debug_on_failure = boolean
end

o.on("--[no-]gc-stress",
"Enable GC.stress only while each test is running",
"(#{@gc_stress})") do |boolean|
@gc_stress = boolean
end

ADDITIONAL_OPTIONS.each do |option_builder|
option_builder.call(self, o)
end
Expand Down Expand Up @@ -454,6 +462,9 @@ def run
if @stop_on_failure
@runner_options[:listeners] << StopOnFailureListener.new
end
if @gc_stress
@runner_options[:listeners] << GCStressListener.new
end
change_work_directory do
runner.run(suite, @runner_options).passed?
end
Expand Down Expand Up @@ -572,6 +583,20 @@ def attach_to_mediator(mediator)
end
end
end

class GCStressListener
def attach_to_mediator(mediator)
mediator.add_listener(TestCase::STARTED) do |test|
GC.start
GC.stress = true
end

mediator.add_listener(TestCase::FINISHED) do |test|
GC.start
GC.stress = false
end
end
end
end
end
end
Expand Down

0 comments on commit bdd1668

Please sign in to comment.