Skip to content

Commit 813ea12

Browse files
authored
Fix NoMemoryError problem with RBS tests + MSVC Ruby (#363)
GitHub: Fix GH-358 If we refer `@suite` from `@options`, `@suite` may not be GC-ed because `@options` may be live longer than a `TestRunner`. For example, `AutoRunner`'s `@runner_options` may be `@options` and `AutoRunner` may be live longer than `TestRunner`.
1 parent 745d395 commit 813ea12

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

lib/test/unit/ui/testrunnermediator.rb

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,22 @@ def run
3636
AutoRunner.need_auto_run = false
3737

3838
result = create_result
39+
options = @options.dup
40+
# We should not keep @suite in @options because @options may
41+
# be live longer than this instance. For example,
42+
# AutoRunner's @runner_options is @options in this instance
43+
# and AutoRunner is live longer than this instance. We can
44+
# dup @options to avoid @suite's life time longer.
45+
options[:test_suite] = @suite
46+
options[:event_listener] = lambda do |channel, value|
47+
notify_listeners(channel, value)
48+
end
3949

4050
Test::Unit.run_at_start_hooks
4151
start_time = Time.now
4252
begin
4353
with_listener(result) do
44-
event_listener = lambda do |channel, value|
45-
notify_listeners(channel, value)
46-
end
47-
@options[:event_listener] = event_listener
48-
@options[:test_suite] = @suite
49-
@test_suite_runner_class.run_all_tests(result, @options) do |run_context|
54+
@test_suite_runner_class.run_all_tests(result, options) do |run_context|
5055
catch do |stop_tag|
5156
result.stop_tag = stop_tag
5257
notify_listeners(RESET, @suite.size)
@@ -76,7 +81,9 @@ def run_suite(result=nil, run_context: nil)
7681
run
7782
else
7883
worker_context = WorkerContext.new(nil, run_context, result)
79-
@suite.run(worker_context, &@options[:event_listener])
84+
@suite.run(worker_context) do |channel, value|
85+
notify_listeners(channel, value)
86+
end
8087
end
8188
end
8289

0 commit comments

Comments
 (0)