Skip to content

Commit b326b7e

Browse files
luke-gruberpeterzhu2118
authored andcommitted
test_all_ractors_multi_ractor: WIP ruby tests passing
1 parent f099af0 commit b326b7e

5 files changed

Lines changed: 42 additions & 29 deletions

File tree

test/ruby/test_array.rb

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -660,14 +660,16 @@ def test_concat
660660
assert_raise(TypeError) { @cls[0].concat(:foo) }
661661
assert_raise(FrozenError) { @cls[0].freeze.concat(:foo) }
662662

663-
a = @cls[nil]
664-
def (x = Object.new).to_ary
665-
ary = Array.new(2)
666-
ary << [] << [] << :ok
663+
unless multiple_ractors?
664+
a = @cls[nil]
665+
def (x = Object.new).to_ary
666+
ary = Array.new(2)
667+
ary << [] << [] << :ok
668+
end
669+
EnvUtil.under_gc_stress {a.concat(x)}
670+
GC.start
671+
assert_equal(:ok, a.last)
667672
end
668-
EnvUtil.under_gc_stress {a.concat(x)}
669-
GC.start
670-
assert_equal(:ok, a.last)
671673
end
672674

673675
def test_count
@@ -1476,6 +1478,7 @@ def test_replace
14761478
end
14771479

14781480
def test_replace_wb_variable_width_alloc
1481+
omit "not working properly across ractors" if multiple_ractors?
14791482
small_embed = []
14801483
4.times { GC.start } # age small_embed
14811484
large_embed = [1, 2, 3, 4, 5, Array.new] # new young object
@@ -2444,11 +2447,13 @@ def test_product
24442447
assert_equal(@cls[], @cls[1,2].product([]))
24452448

24462449
bug3394 = '[ruby-dev:41540]'
2447-
acc = []
2448-
EnvUtil.under_gc_stress {[1,2].product([3,4,5],[6,8]){|array| acc << array}}
2449-
assert_equal([[1, 3, 6], [1, 3, 8], [1, 4, 6], [1, 4, 8], [1, 5, 6], [1, 5, 8],
2450-
[2, 3, 6], [2, 3, 8], [2, 4, 6], [2, 4, 8], [2, 5, 6], [2, 5, 8]],
2451-
acc, bug3394)
2450+
unless multiple_ractors?
2451+
acc = []
2452+
EnvUtil.under_gc_stress {[1,2].product([3,4,5],[6,8]){|array| acc << array}}
2453+
assert_equal([[1, 3, 6], [1, 3, 8], [1, 4, 6], [1, 4, 8], [1, 5, 6], [1, 5, 8],
2454+
[2, 3, 6], [2, 3, 8], [2, 4, 6], [2, 4, 8], [2, 5, 6], [2, 5, 8]],
2455+
acc, bug3394)
2456+
end
24522457

24532458
def (o = Object.new).to_ary; GC.start; [3,4] end
24542459
acc = [1,2].product(*[o]*10)

test/ruby/test_ast.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ def test_parse_raises_syntax_error
210210
end
211211

212212
def test_parse_file_raises_syntax_error
213+
omit "Tempfile" unless main_ractor?
213214
Tempfile.create(%w"test_ast .rb") do |f|
214215
f.puts "end"
215216
f.close
@@ -377,6 +378,7 @@ def test_node_id_for_backtrace_location_raises_argument_error
377378

378379
def test_of_proc_and_method
379380
omit if ParserSupport.prism_enabled? || ParserSupport.prism_enabled_in_subprocess?
381+
omit "Tempfile" unless main_ractor?
380382

381383
proc = Proc.new { 1 + 2 }
382384
method = self.method(__method__)

test/ruby/test_optimization.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,7 @@ def test_opt_new_with_safe_navigation
12251225
end
12261226

12271227
def test_opt_new
1228+
omit "RubyVM::Iseq.compile/eval not working across multiple ractors" if multiple_ractors?
12281229
pos_initialize = "
12291230
def initialize a, b
12301231
@a = a

tool/lib/test/unit.rb

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,8 +1736,8 @@ def _run_suite suite, type
17361736
ractor_results = []
17371737
while rs.any?
17381738
r, obj = Ractor.select(*rs)
1739-
_inst, runner, res = *obj
1740-
ractor_results << [res, runner]
1739+
inst, runner, res = *obj
1740+
ractor_results << [res, inst, runner]
17411741
rs.delete(r)
17421742
end
17431743
# ractors done
@@ -1747,11 +1747,12 @@ def _run_suite suite, type
17471747
self.skips = old_skips
17481748
self.assertion_count = old_assertion_count
17491749
self.test_count = old_test_count
1750-
res = ""
1751-
ractor_results.each do |(res0, runner)|
1752-
res += res0
1753-
_merge_results_from_ractor(runner)
1750+
res = +""
1751+
ractor_results.each do |(res0, inst, runner)|
1752+
res << res0
1753+
_merge_results_from_ractor(inst, runner)
17541754
end
1755+
inst._assertions = self.assertion_count - old_assertion_count
17551756
res
17561757
else
17571758
inst.run self
@@ -1776,13 +1777,13 @@ def _run_suite suite, type
17761777
def __init_runner(runner)
17771778
end
17781779

1779-
def _merge_results_from_ractor(runner_cpy)
1780-
@report += runner_cpy.report
1781-
@failures += runner_cpy.failures
1782-
@errors += runner_cpy.errors
1783-
@skips += runner_cpy.skips
1784-
@assertion_count += runner_cpy.assertion_count
1785-
@test_count += runner_cpy.test_count
1780+
def _merge_results_from_ractor(inst, runner_cpy)
1781+
self.report += runner_cpy.report
1782+
self.failures += runner_cpy.failures
1783+
self.errors += runner_cpy.errors
1784+
self.skips += runner_cpy.skips
1785+
self.assertion_count += inst._assertions
1786+
self.test_count += runner_cpy.test_count
17861787
end
17871788

17881789
def _start_method(inst)
@@ -1852,7 +1853,8 @@ def _run args = []
18521853
ractors_num = ENV["RUBY_TESTS_WITH_RACTORS"].to_i
18531854

18541855
if ractors_num > 0
1855-
puts "\nNOTE: Running tests inside ractors (each test method inside #{ractors_num} ractors)"
1856+
puts "\nNOTE: Running tests inside ractors (each test method inside #{ractors_num} " \
1857+
"ractor#{ractors_num > 1 ? 's' : ''})"
18561858
end
18571859

18581860
self.class.plugins.each do |plugin|

tool/lib/test/unit/testcase.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,18 @@ def non_main_ractor?
5959
not main_ractor?
6060
end
6161

62+
def multiple_ractors?
63+
ENV["RUBY_TESTS_WITH_RACTORS"].to_i > 1
64+
end
65+
6266
# In order to guard generating methods dynamically that will run inside a ractor
6367
def will_run_in_non_main_ractor?
64-
ENV["RUBY_TESTS_WITH_RACTORS"]
68+
ENV["RUBY_TESTS_WITH_RACTORS"].to_i > 0
6569
end
6670

6771
def will_run_in_main_ractor?
6872
not will_run_in_non_main_ractor?
6973
end
70-
7174
end
7275

7376
##
@@ -219,8 +222,8 @@ def run_test(name)
219222
progname, $0 = $0, "#{$0}: #{self.class}##{name}" if main_ractor?
220223
self.__send__(name)
221224
ensure
222-
$@.delete(RUN_TEST_TRACE) if $@
223225
if main_ractor?
226+
$@.delete(RUN_TEST_TRACE) if $@
224227
$0 = progname
225228
end
226229
end

0 commit comments

Comments
 (0)