Skip to content

Commit 0d95446

Browse files
committed
Fix more tests for test-all with multiple ractors
1 parent b5bd4e8 commit 0d95446

9 files changed

Lines changed: 81 additions & 68 deletions

test/ruby/test_basicinstructions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Class
1010
class TestBasicInstructions < Test::Unit::TestCase
1111

1212
def setup
13-
omit "Lots of unfrozen strings in constants" if non_main_ractor?
13+
omit "Lots of unfrozen strings in constants" unless main_ractor?
1414
end
1515

1616
def test_immediates

test/ruby/test_beginendblock.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def test_errinfo_at_exit
167167

168168
if defined?(fork)
169169
def test_internal_errinfo_at_exit
170-
omit "at_exit handlers cannot use ractor-local objects" if non_main_ractor?
170+
omit "fork" unless main_ractor?
171171
# TODO: use other than break-in-fork to throw an internal
172172
# error info.
173173
error, pid, status = IO.pipe do |r, w|

test/ruby/test_enumerator.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,10 +496,12 @@ def test_generator
496496

497497
assert_raise(LocalJumpError) {Enumerator::Generator.new}
498498
assert_raise(TypeError) {Enumerator::Generator.new(1)}
499-
obj = eval("class C\u{1f5ff}; self; end").new
500-
assert_raise_with_message(TypeError, /C\u{1f5ff}/) {
501-
Enumerator::Generator.new(obj)
502-
}
499+
unless multiple_ractors?
500+
obj = eval("class C\u{1f5ff}; self; end").new
501+
assert_raise_with_message(TypeError, /C\u{1f5ff}/) {
502+
Enumerator::Generator.new(obj)
503+
}
504+
end
503505
end
504506

505507
def test_generator_args

test/ruby/test_file_exhaustive.rb

Lines changed: 63 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -928,17 +928,19 @@ def test_expand_path_encoding
928928

929929
def test_expand_path_encoding_filesystem
930930
omit "global side effects" if multiple_ractors?
931-
home = ENV["HOME"]
932-
ENV["HOME"] = "#{DRIVE}/UserHome"
931+
begin
932+
home = ENV["HOME"]
933+
ENV["HOME"] = "#{DRIVE}/UserHome"
933934

934-
path = "~".encode("US-ASCII")
935-
dir = "C:/".encode("IBM437")
936-
fs = Encoding.find("filesystem")
935+
path = "~".encode("US-ASCII")
936+
dir = "C:/".encode("IBM437")
937+
fs = Encoding.find("filesystem")
937938

938-
assert_equal fs, File.expand_path(path).encoding
939-
assert_equal fs, File.expand_path(path, dir).encoding
940-
ensure
941-
ENV["HOME"] = home if home
939+
assert_equal fs, File.expand_path(path).encoding
940+
assert_equal fs, File.expand_path(path, dir).encoding
941+
ensure
942+
ENV["HOME"] = home
943+
end
942944
end
943945

944946
UnknownUserHome = "~foo_bar_baz_unknown_user_wahaha".freeze
@@ -963,31 +965,31 @@ def test_expand_path_home
963965
ENV["HOME"] = "."
964966
assert_raise(ArgumentError, bug3630) { File.expand_path("~") }
965967
ensure
966-
if home
967-
ENV["HOME"] = home
968-
ENV["HOMEDRIVE"] = home_drive
969-
ENV["HOMEPATH"] = home_path
970-
ENV["USERPROFILE"] = user_profile
971-
end
968+
ENV["HOME"] = home
969+
ENV["HOMEDRIVE"] = home_drive
970+
ENV["HOMEPATH"] = home_path
971+
ENV["USERPROFILE"] = user_profile
972972
end
973973
end
974974

975975
def test_expand_path_home_dir_string
976976
omit "global side effects" if multiple_ractors?
977-
home = ENV["HOME"]
978-
new_home = "#{DRIVE}/UserHome"
979-
ENV["HOME"] = new_home
980-
bug8034 = "[ruby-core:53168]"
981-
982-
assert_equal File.join(new_home, "foo"), File.expand_path("foo", "~"), bug8034
983-
assert_equal File.join(new_home, "bar", "foo"), File.expand_path("foo", "~/bar"), bug8034
984-
985-
assert_raise(ArgumentError) { File.expand_path(".", UnknownUserHome) }
986-
assert_nothing_raised(ArgumentError) { File.expand_path("#{DRIVE}/", UnknownUserHome) }
987-
ENV["HOME"] = "#{DRIVE}UserHome"
988-
assert_raise(ArgumentError) { File.expand_path("~") }
989-
ensure
990-
ENV["HOME"] = home if home
977+
begin
978+
home = ENV["HOME"]
979+
new_home = "#{DRIVE}/UserHome"
980+
ENV["HOME"] = new_home
981+
bug8034 = "[ruby-core:53168]"
982+
983+
assert_equal File.join(new_home, "foo"), File.expand_path("foo", "~"), bug8034
984+
assert_equal File.join(new_home, "bar", "foo"), File.expand_path("foo", "~/bar"), bug8034
985+
986+
assert_raise(ArgumentError) { File.expand_path(".", UnknownUserHome) }
987+
assert_nothing_raised(ArgumentError) { File.expand_path("#{DRIVE}/", UnknownUserHome) }
988+
ENV["HOME"] = "#{DRIVE}UserHome"
989+
assert_raise(ArgumentError) { File.expand_path("~") }
990+
ensure
991+
ENV["HOME"] = home
992+
end
991993
end
992994

993995
if /mswin|mingw/ =~ RUBY_PLATFORM
@@ -1110,33 +1112,39 @@ def test_expand_path_converts_a_pathname_which_starts_with_a_slash_using_a_curre
11101112

11111113
def test_expand_path_converts_a_pathname_to_an_absolute_pathname_using_home_as_base
11121114
omit "global side effects" if multiple_ractors?
1113-
old_home = ENV["HOME"]
1114-
home = ENV["HOME"] = "#{DRIVE}/UserHome"
1115-
assert_equal(home, File.expand_path("~"))
1116-
assert_equal(home, File.expand_path("~", "C:/FooBar"))
1117-
assert_equal(File.join(home, "a"), File.expand_path("~/a", "C:/FooBar"))
1118-
ensure
1119-
ENV["HOME"] = old_home if old_home
1115+
begin
1116+
old_home = ENV["HOME"]
1117+
home = ENV["HOME"] = "#{DRIVE}/UserHome"
1118+
assert_equal(home, File.expand_path("~"))
1119+
assert_equal(home, File.expand_path("~", "C:/FooBar"))
1120+
assert_equal(File.join(home, "a"), File.expand_path("~/a", "C:/FooBar"))
1121+
ensure
1122+
ENV["HOME"] = old_home
1123+
end
11201124
end
11211125

11221126
def test_expand_path_converts_a_pathname_to_an_absolute_pathname_using_unc_home
11231127
omit "global side effects" if multiple_ractors?
1124-
old_home = ENV["HOME"]
1125-
unc_home = ENV["HOME"] = "//UserHome"
1126-
assert_equal(unc_home, File.expand_path("~"))
1127-
ensure
1128-
ENV["HOME"] = old_home if old_home
1128+
begin
1129+
old_home = ENV["HOME"]
1130+
unc_home = ENV["HOME"] = "//UserHome"
1131+
assert_equal(unc_home, File.expand_path("~"))
1132+
ensure
1133+
ENV["HOME"] = old_home
1134+
end
11291135
end if DRIVE
11301136

11311137
def test_expand_path_does_not_modify_a_home_string_argument
11321138
omit "global side effects" if multiple_ractors?
1133-
old_home = ENV["HOME"]
1134-
home = ENV["HOME"] = "#{DRIVE}/UserHome"
1135-
str = "~/a"
1136-
assert_equal("#{home}/a", File.expand_path(str))
1137-
assert_equal("~/a", str)
1138-
ensure
1139-
ENV["HOME"] = old_home if old_home
1139+
begin
1140+
old_home = ENV["HOME"]
1141+
home = ENV["HOME"] = "#{DRIVE}/UserHome"
1142+
str = "~/a"
1143+
assert_equal("#{home}/a", File.expand_path(str))
1144+
assert_equal("~/a", str)
1145+
ensure
1146+
ENV["HOME"] = old_home
1147+
end
11401148
end
11411149

11421150
def test_expand_path_raises_argument_error_for_any_supplied_username
@@ -1157,11 +1165,13 @@ def test_expand_path_error_for_nonexistent_username
11571165

11581166
def test_expand_path_error_for_non_absolute_home
11591167
omit "global side effects" if multiple_ractors?
1160-
old_home = ENV["HOME"]
1161-
ENV["HOME"] = "./UserHome"
1162-
assert_raise_with_message(ArgumentError, /non-absolute home/) {File.expand_path("~")}
1163-
ensure
1164-
ENV["HOME"] = old_home if old_home
1168+
begin
1169+
old_home = ENV["HOME"]
1170+
ENV["HOME"] = "./UserHome"
1171+
assert_raise_with_message(ArgumentError, /non-absolute home/) {File.expand_path("~")}
1172+
ensure
1173+
ENV["HOME"] = old_home
1174+
end
11651175
end
11661176

11671177
def test_expand_path_raises_a_type_error_if_not_passed_a_string_type

test/ruby/test_io.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ def test_copy_stream_file_to_pipe
702702
if have_nonblock?
703703
def test_copy_stream_no_busy_wait
704704
omit "multiple threads already active" if Thread.list.size > 1
705+
omit "unpredictable" unless main_ractor?
705706

706707
msg = 'r58534 [ruby-core:80969] [Backport #13533]'
707708
IO.pipe do |r,w|

test/ruby/test_method.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,7 @@ def m2
15801580
end)
15811581

15821582
def test_method_in_method_visibility_should_be_public
1583+
omit "racy" if multiple_ractors?
15831584
MethodInMethodClass_Setup.call
15841585

15851586
assert_equal([:m1].sort, MethodInMethodClass.public_instance_methods(false).sort)

test/ruby/test_shapes.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def test_too_complex
126126
end
127127

128128
def test_ordered_alloc_is_not_complex
129-
pend "ObjectSpace.dump" if non_main_ractor?
129+
pend "ObjectSpace.dump" unless main_ractor?
130130
5.times { OrderedAlloc.new.add_ivars }
131131
obj = JSON.parse(ObjectSpace.dump(OrderedAlloc))
132132
assert_operator obj["variation_count"], :<, RubyVM::Shape::SHAPE_MAX_VARIATIONS
@@ -180,7 +180,7 @@ def test_removing_when_too_many_ivs_on_class
180180

181181
def test_removing_when_too_many_ivs_on_module
182182
# could be safe due to not having a constant attached
183-
pend "module ivars" if non_main_ractor?
183+
pend "module ivars" unless main_ractor?
184184
obj = Module.new
185185

186186
(MANY_IVS + 2).times do

test/ruby/test_signal.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
require 'tempfile'
55

66
class TestSignal < Test::Unit::TestCase
7+
8+
def setup
9+
omit "racy" unless main_ractor?
10+
end
11+
712
def test_signal
8-
omit "signals run in main ractor" if non_main_ractor?
913
begin
1014
x = 0
1115
oldtrap = Signal.trap(:INT) {|sig| x = 2 }
@@ -27,7 +31,6 @@ def test_signal
2731
end if Process.respond_to?(:kill)
2832

2933
def test_signal_process_group
30-
omit "Process.spawn" unless main_ractor?
3134
bug4362 = '[ruby-dev:43169]'
3235
assert_nothing_raised(bug4362) do
3336
cmd = [ EnvUtil.rubybin, '--disable=gems' '-e', 'sleep 10' ]
@@ -41,7 +44,6 @@ def test_signal_process_group
4144
Process.respond_to?(:pgroup) # for mswin32
4245

4346
def test_exit_action
44-
pend "Timeout" if non_main_ractor?
4547
if Signal.list[sig = "USR1"]
4648
term = :TERM
4749
else
@@ -100,7 +102,6 @@ def test_interrupt
100102
end
101103

102104
def test_signal2
103-
pend "Timeout" if non_main_ractor?
104105
begin
105106
x = false
106107
oldtrap = Signal.trap(:INT) {|sig| x = true }
@@ -136,7 +137,6 @@ def o.to_str; "SIGINT"; end
136137
end if Process.respond_to?(:kill)
137138

138139
def test_trap
139-
omit "not ractor safe" unless main_ractor?
140140
begin
141141
oldtrap = Signal.trap(:INT) {|sig| }
142142

@@ -265,7 +265,6 @@ def test_trap_puts
265265
end if Process.respond_to?(:kill)
266266

267267
def test_hup_me
268-
pend "Timeout" if non_main_ractor?
269268
# [Bug #7951] [ruby-core:52864]
270269
# This is MRI specific spec. ruby has no guarantee
271270
# that signal will be deliverd synchronously.
@@ -318,7 +317,6 @@ def test_signal_list_dedupe_keys
318317
def test_self_stop
319318
omit unless Process.respond_to?(:fork)
320319
omit unless defined?(Process::WUNTRACED)
321-
omit "fork" unless main_ractor?
322320

323321
# Make a process that stops itself
324322
child_pid = fork do

test/ruby/test_thread_cv.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def test_condvar_wait_deadlock_2
137137
end
138138

139139
def test_condvar_timed_wait
140+
omit "unpredictable" if multiple_ractors?
140141
mutex = Thread::Mutex.new
141142
condvar = Thread::ConditionVariable.new
142143
timeout = 0.3

0 commit comments

Comments
 (0)