Skip to content

Commit b6d0961

Browse files
luke-gruberpeterzhu2118
authored andcommitted
test_all_ractors_multi_ractor: another WIP
1 parent b326b7e commit b6d0961

27 files changed

Lines changed: 166 additions & 64 deletions

test/ruby/test_backtrace.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ def test_caller_locations_to_s_inspect
258258
end
259259

260260
def test_caller_locations_path
261+
omit "Tempfile" unless main_ractor?
261262
loc, = caller_locations(0, 1)
262263
assert_equal(__FILE__, loc.path)
263264
Tempfile.create(%w"caller_locations .rb") do |f|
@@ -269,6 +270,7 @@ def test_caller_locations_path
269270
end
270271

271272
def test_caller_locations_absolute_path
273+
omit "Tempfile" unless main_ractor?
272274
loc, = caller_locations(0, 1)
273275
assert_equal(__FILE__, loc.absolute_path)
274276
Tempfile.create(%w"caller_locations .rb") do |f|
@@ -279,6 +281,7 @@ def test_caller_locations_absolute_path
279281
end
280282

281283
def test_caller_locations_lineno
284+
omit "Tempfile" unless main_ractor?
282285
loc, = caller_locations(0, 1)
283286
assert_equal(__LINE__-1, loc.lineno)
284287
Tempfile.create(%w"caller_locations .rb") do |f|

test/ruby/test_beginendblock.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def test_exitcode_in_at_exit
7373
end
7474

7575
def test_propagate_exit_code
76+
omit "TODO: look into this. Getting unexpected values but can't reproduce it in non-test environment"
7677
ruby = EnvUtil.rubybin
7778
assert_equal false, system(ruby, '-e', 'at_exit{exit 2}')
7879
assert_equal 2, $?.exitstatus
@@ -119,6 +120,7 @@ def test_nested_at_exit
119120
end
120121

121122
def test_rescue_at_exit
123+
omit "subprocess" unless main_ractor?
122124
bug5218 = '[ruby-core:43173][Bug #5218]'
123125
cmd = [
124126
"raise 'X' rescue nil",

test/ruby/test_class.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,11 @@ def test_check_inheritable
244244
assert_raise(TypeError) { Class.new(c) }
245245
assert_raise(TypeError) { Class.new(Class) }
246246
assert_raise(TypeError) { eval("class Foo < Class; end") }
247-
m = "M\u{1f5ff}"
248-
o = Class.new {break eval("class #{m}; self; end.new")}
249-
assert_raise_with_message(TypeError, /#{m}/) {Class.new(o)}
247+
if main_ractor?
248+
m = "M\u{1f5ff}"
249+
o = Class.new {break eval("class #{m}; self; end.new")}
250+
assert_raise_with_message(TypeError, /#{m}/) {Class.new(o)}
251+
end
250252
end
251253

252254
def test_initialize_copy

test/ruby/test_compile_prism.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
# This file is organized to match itemization in https://github.com/ruby/prism/issues/1335
44
module Prism
55
class TestCompilePrism < Test::Unit::TestCase
6+
def setup
7+
omit "Not ractor safe" if multiple_ractors?
8+
end
9+
610
def test_iseq_has_node_id
711
code = "proc { <<END }\n hello\nEND"
812
iseq = RubyVM::InstructionSequence.compile_prism(code)

test/ruby/test_defined.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ def test_super_toplevel
391391
end
392392

393393
def test_respond_to
394+
omit "Warning[]= used" if multiple_ractors?
394395
obj = "#{self.class.name}##{__method__}"
395396
class << obj
396397
def respond_to?(mid)

test/ruby/test_dir_m17n.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
require '-test-/file'
55

66
class TestDir_M17N < Test::Unit::TestCase
7+
def setup
8+
omit "Uses Dir.chdir" if multiple_ractors?
9+
end
10+
711
def with_tmpdir
812
Dir.mktmpdir {|dir|
913
Dir.chdir(dir) {

test/ruby/test_enumerator.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ def test_with_index
129129

130130
def test_with_index_under_gc_compact_stress
131131
omit "compaction doesn't work well on s390x" if RUBY_PLATFORM =~ /s390x/ # https://github.com/ruby/ruby/pull/5077
132+
omit "EnvUtil.under_gc_compact_stress" if multiple_ractors?
132133
EnvUtil.under_gc_compact_stress do
133134
assert_equal([[1, 0], [2, 1], [3, 2]], @obj.to_enum(:foo, 1, 2, 3).with_index.to_a)
134135
assert_equal([[1, 5], [2, 6], [3, 7]], @obj.to_enum(:foo, 1, 2, 3).with_index(5).to_a)
@@ -865,6 +866,7 @@ def test_lazy_chain
865866

866867
def test_lazy_chain_under_gc_compact_stress
867868
omit "compaction doesn't work well on s390x" if RUBY_PLATFORM =~ /s390x/ # https://github.com/ruby/ruby/pull/5077
869+
omit "EnvUtil.under_gc_compact_stress" if multiple_ractors?
868870
EnvUtil.under_gc_compact_stress do
869871
ea = (10..).lazy.select(&:even?).take(10)
870872
ed = (20..).lazy.select(&:odd?)

test/ruby/test_env.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@ def assert_invalid_env(msg = nil)
2323
end
2424

2525
def setup
26+
omit "unpredictable results" if multiple_ractors?
2627
@verbose = $VERBOSE
2728
@backup = ENV.to_hash
2829
ENV.delete('test')
2930
ENV.delete('TEST')
3031
end
3132

3233
def teardown
33-
$VERBOSE = @verbose
34-
ENV.clear
35-
@backup.each {|k, v| ENV[k] = v }
34+
if @verbose
35+
$VERBOSE = @verbose
36+
ENV.clear
37+
@backup.each {|k, v| ENV[k] = v }
38+
end
3639
end
3740

3841
def test_bracket

test/ruby/test_eval.rb

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -404,24 +404,26 @@ def test_eval_orig
404404
end
405405
assert(!bad)
406406

407-
# !! use class_eval to avoid nested definition
408-
x = self.class.class_eval %q(
409-
module EvTest
410-
EVTEST1 = 25
411-
evtest2 = 125
412-
evtest2 = evtest2
413-
binding
407+
unless multiple_ractors?
408+
# !! use class_eval to avoid nested definition
409+
x = self.class.class_eval %q(
410+
module EvTest
411+
EVTEST1 = 25
412+
evtest2 = 125
413+
evtest2 = evtest2
414+
binding
415+
end
416+
)
417+
assert_equal(25, eval("EVTEST1", x)) # constant in module
418+
assert_equal(125, eval("evtest2", x)) # local var in module
419+
bad = true
420+
begin
421+
eval("EVTEST1")
422+
rescue NameError # must raise error
423+
bad = false
414424
end
415-
)
416-
assert_equal(25, eval("EVTEST1", x)) # constant in module
417-
assert_equal(125, eval("evtest2", x)) # local var in module
418-
bad = true
419-
begin
420-
eval("EVTEST1")
421-
rescue NameError # must raise error
422-
bad = false
425+
assert(!bad)
423426
end
424-
assert(!bad)
425427

426428
x = binding
427429
eval "i = 1", x
@@ -453,7 +455,7 @@ module EvTest
453455

454456
self.class.class_eval do
455457
remove_const :EvTest
456-
end
458+
end unless multiple_ractors?
457459
end
458460

459461
def test_nil_instance_eval_cvar
@@ -539,6 +541,7 @@ def test_eval_raise
539541
end
540542

541543
def test_eval_with_toplevel_binding # [ruby-dev:37142]
544+
omit "subprocess" unless main_ractor?
542545
ruby("-e", "x = 0; eval('p x', TOPLEVEL_BINDING)") do |f|
543546
f.close_write
544547
assert_equal("0", f.read.chomp)

test/ruby/test_exception.rb

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ def test_raise_with_wrong_number_of_arguments
394394
end
395395

396396
def test_type_error_message_encoding
397+
omit "global side effects" if multiple_ractors?
397398
c = eval("Module.new do break class C\u{4032}; self; end; end")
398399
o = c.new
399400
assert_raise_with_message(TypeError, /C\u{4032}/) do
@@ -446,6 +447,7 @@ def test_errat
446447
end
447448

448449
def test_thread_signal_location
450+
omit "subprocess" unless main_ractor?
449451
# pend('TODO: a known bug [Bug #14474]')
450452
_, stderr, _ = EnvUtil.invoke_ruby(%w"--disable-gems -d", <<-RUBY, false, true)
451453
Thread.start do
@@ -561,6 +563,7 @@ def test_errno_constants
561563
end
562564

563565
def test_too_many_args_in_eval
566+
omit "TODO: freezes process" if multiple_ractors?
564567
bug5720 = '[ruby-core:41520]'
565568
arg_string = (0...140000).to_a.join(", ")
566569
assert_raise(SystemStackError, bug5720) {eval "raise(#{arg_string})"}
@@ -1065,6 +1068,7 @@ def test_message_of_name_error
10651068
end
10661069

10671070
def capture_warning_warn(category: false)
1071+
omit "global side effects" if multiple_ractors?
10681072
verbose = $VERBOSE
10691073
categories = Warning.categories.to_h {|cat| [cat, Warning[cat]]}
10701074
warning = []
@@ -1090,13 +1094,15 @@ def capture_warning_warn(category: false)
10901094

10911095
return warning
10921096
ensure
1093-
$VERBOSE = verbose
1094-
categories.each {|cat, flag| Warning[cat] = flag}
1095-
1096-
::Warning.class_eval do
1097-
remove_method :warn
1098-
alias_method :warn, :warn2
1099-
remove_method :warn2
1097+
if verbose
1098+
$VERBOSE = verbose
1099+
categories.each {|cat, flag| Warning[cat] = flag}
1100+
1101+
::Warning.class_eval do
1102+
remove_method :warn
1103+
alias_method :warn, :warn2
1104+
remove_method :warn2
1105+
end
11001106
end
11011107
end
11021108

@@ -1189,6 +1195,7 @@ def warn(message)
11891195
end
11901196

11911197
def test_warning_category
1198+
omit "global side effects" if multiple_ractors?
11921199
assert_raise(TypeError) {Warning[nil]}
11931200
assert_raise(ArgumentError) {Warning[:XXXX]}
11941201

@@ -1309,12 +1316,14 @@ def test_full_message
13091316

13101317
test_method = "def foo; raise 'testerror'; end"
13111318

1312-
out1, err1, status1 = EnvUtil.invoke_ruby(['-e', "#{test_method}; begin; foo; rescue => e; puts e.full_message; end"], '', true, true)
1313-
assert_predicate(status1, :success?)
1314-
assert_empty(err1, "expected nothing wrote to $stdout by #full_message")
1319+
if main_ractor?
1320+
out1, err1, status1 = EnvUtil.invoke_ruby(['-e', "#{test_method}; begin; foo; rescue => e; puts e.full_message; end"], '', true, true)
1321+
assert_predicate(status1, :success?)
1322+
assert_empty(err1, "expected nothing wrote to $stdout by #full_message")
13151323

1316-
_, err2, status1 = EnvUtil.invoke_ruby(['-e', "#{test_method}; begin; foo; end"], '', true, true)
1317-
assert_equal(err2, out1)
1324+
_, err2, status1 = EnvUtil.invoke_ruby(['-e', "#{test_method}; begin; foo; end"], '', true, true)
1325+
assert_equal(err2, out1)
1326+
end
13181327

13191328
e = RuntimeError.new("a\n")
13201329
message = assert_nothing_raised(ArgumentError, proc {e.pretty_inspect}) do
@@ -1447,6 +1456,7 @@ def test_detailed_message
14471456

14481457
def test_detailed_message_under_gc_compact_stress
14491458
omit "compaction doesn't work well on s390x" if RUBY_PLATFORM =~ /s390x/ # https://github.com/ruby/ruby/pull/5077
1459+
omit "gc_compact_stress" if multiple_ractors?
14501460
EnvUtil.under_gc_compact_stress do
14511461
e = RuntimeError.new("foo\nbar\nbaz")
14521462
assert_equal("foo (RuntimeError)\nbar\nbaz", e.detailed_message)

0 commit comments

Comments
 (0)