Skip to content

Commit 4a3a2d7

Browse files
committed
More ractor test-all fixes
1 parent 5c71182 commit 4a3a2d7

39 files changed

+352
-148
lines changed

test/ruby/test_argf.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class TestArgf < Test::Unit::TestCase
99
def setup
10-
omit "ARGF is not shareable" if non_main_ractor?
10+
omit "ARGF is not shareable" unless main_ractor?
1111
@tmpdir = Dir.mktmpdir
1212
@tmp_count = 0
1313
@t1 = make_tempfile("argf-foo", %w"1 2", binmode: true)
@@ -16,7 +16,7 @@ def setup
1616
end
1717

1818
def teardown
19-
return if non_main_ractor?
19+
return unless main_ractor?
2020
FileUtils.rmtree(@tmpdir)
2121
end
2222

test/ruby/test_autoload.rb

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
require 'tempfile'
44

55
class TestAutoload < Test::Unit::TestCase
6+
def setup
7+
pend "autoload" unless main_ractor?
8+
end
9+
610
def test_autoload_so
711
# Date is always available, unless excluded intentionally.
812
assert_in_out_err([], <<-INPUT, [], [])
@@ -66,7 +70,7 @@ def test_autoload_p
6670
end
6771

6872
def test_autoload_p_with_static_extensions
69-
pend "belonging issue" if non_main_ractor?
73+
pend "belonging issue" unless main_ractor?
7074
require 'rbconfig'
7175
omit unless RbConfig::CONFIG['EXTSTATIC'] == 'static'
7276
begin
@@ -85,7 +89,7 @@ def test_autoload_p_with_static_extensions
8589
end
8690

8791
def test_autoload_with_unqualified_file_name # [ruby-core:69206]
88-
omit "global variable access" if non_main_ractor?
92+
omit "global variable access" unless main_ractor?
8993
Object.send(:remove_const, :A) if Object.const_defined?(:A)
9094

9195
lp = $LOAD_PATH.dup
@@ -114,7 +118,7 @@ module A
114118
end
115119

116120
def test_require_explicit
117-
pend "Tempfile" if non_main_ractor?
121+
pend "Tempfile" unless main_ractor?
118122
Tempfile.create(['autoload', '.rb']) {|file|
119123
file.puts 'class Object; AutoloadTest = 1; end'
120124
file.close
@@ -131,7 +135,7 @@ def test_require_explicit
131135
end
132136

133137
def test_threaded_accessing_constant
134-
pend "Tempfile" if non_main_ractor?
138+
pend "Tempfile" unless main_ractor?
135139
# Suppress "warning: loading in progress, circular require considered harmful"
136140
EnvUtil.default_warning {
137141
Tempfile.create(['autoload', '.rb']) {|file|
@@ -152,7 +156,7 @@ def test_threaded_accessing_constant
152156
end
153157

154158
def test_threaded_accessing_inner_constant
155-
pend "Tempfile" if non_main_ractor?
159+
pend "Tempfile" unless main_ractor?
156160
# Suppress "warning: loading in progress, circular require considered harmful"
157161
EnvUtil.default_warning {
158162
Tempfile.create(['autoload', '.rb']) {|file|
@@ -173,7 +177,7 @@ def test_threaded_accessing_inner_constant
173177
end
174178

175179
def test_nameerror_when_autoload_did_not_define_the_constant
176-
pend "Tempfile" if non_main_ractor?
180+
pend "Tempfile" unless main_ractor?
177181
verbose_bak, $VERBOSE = $VERBOSE, nil
178182
Tempfile.create(['autoload', '.rb']) {|file|
179183
file.puts ''
@@ -192,7 +196,7 @@ def test_nameerror_when_autoload_did_not_define_the_constant
192196
end
193197

194198
def test_override_autoload
195-
pend "Tempfile" if non_main_ractor?
199+
pend "Tempfile" unless main_ractor?
196200
Tempfile.create(['autoload', '.rb']) {|file|
197201
file.puts ''
198202
file.close
@@ -207,7 +211,7 @@ def test_override_autoload
207211
end
208212

209213
def test_override_while_autoloading
210-
pend "Tempfile" if non_main_ractor?
214+
pend "Tempfile" unless main_ractor?
211215
Tempfile.create(['autoload', '.rb']) {|file|
212216
file.puts 'class AutoloadTest; sleep 0.5; end'
213217
file.close
@@ -259,7 +263,7 @@ def ruby_impl_require
259263
end
260264

261265
def test_require_implemented_in_ruby_is_called
262-
pend "Tempfile" if non_main_ractor?
266+
pend "Tempfile" unless main_ractor?
263267
ruby_impl_require do |called_with|
264268
Tempfile.create(['autoload', '.rb']) {|file|
265269
file.puts 'class AutoloadTest; end'
@@ -277,7 +281,7 @@ def test_require_implemented_in_ruby_is_called
277281
end
278282

279283
def test_autoload_while_autoloading
280-
pend "Tempfile" if non_main_ractor?
284+
pend "Tempfile" unless main_ractor?
281285
ruby_impl_require do |called_with|
282286
Tempfile.create(%w(a .rb)) do |a|
283287
Tempfile.create(%w(b .rb)) do |b|
@@ -407,7 +411,7 @@ class AutoloadTest
407411
end
408412

409413
def test_autoload_fork
410-
pend "Tempfile" if non_main_ractor?
414+
pend "Tempfile" unless main_ractor?
411415
EnvUtil.default_warning do
412416
Tempfile.create(['autoload', '.rb']) {|file|
413417
file.puts 'sleep 0.3; class AutoloadTest; end'

test/ruby/test_class.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ def test_uninitialized
291291
end
292292

293293
def test_nonascii_name
294+
omit "global side effects" if multiple_ractors?
294295
c = eval("class ::C\u{df}; self; end")
295296
assert_equal("C\u{df}", c.name, '[ruby-core:24600]')
296297
c = eval("class C\u{df}; self; end")

test/ruby/test_defined.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ def x; b {return defined?(super)}; end
373373
end
374374

375375
def test_super_in_basic_object
376+
omit "global side effects" if multiple_ractors?
377+
run_ensure = true
376378
BasicObject.class_eval do
377379
def a
378380
defined?(super)
@@ -383,7 +385,7 @@ def a
383385
ensure
384386
BasicObject.class_eval do
385387
undef_method :a if defined?(a)
386-
end
388+
end if run_ensure
387389
end
388390

389391
def test_super_toplevel

test/ruby/test_dir.rb

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
class TestDir < Test::Unit::TestCase
88

99
def setup
10+
omit "lots of Dir.chdir" if multiple_ractors?
1011
@verbose = $VERBOSE
1112
@root = File.realpath(Dir.mktmpdir('__test_dir__'))
1213
@nodir = File.join(@root, "dummy")
@@ -23,6 +24,7 @@ def setup
2324
end
2425

2526
def teardown
27+
return if multiple_ractors?
2628
$VERBOSE = @verbose
2729
FileUtils.remove_entry_secure @root if File.directory?(@root)
2830
ENV.update(@envs) if @envs
@@ -97,7 +99,7 @@ def test_rewind
9799
end
98100

99101
def test_class_chdir
100-
omit "not ractor safe" unless main_ractor?
102+
omit "Dir.chdir" unless main_ractor?
101103
pwd = Dir.pwd
102104
setup_envs
103105

@@ -137,7 +139,7 @@ def test_class_chdir
137139
end
138140

139141
def test_instance_chdir
140-
omit "not ractor safe" unless main_ractor?
142+
omit "Dir.chdir" unless main_ractor?
141143
pwd = Dir.pwd
142144
dir = Dir.new(pwd)
143145
root_dir = Dir.new(@root)
@@ -205,7 +207,7 @@ def Warning.warn(message)
205207
end
206208

207209
def test_chdir_conflict
208-
omit "not ractor safe" unless main_ractor?
210+
omit "Dir.chdir" unless main_ractor?
209211
pwd = Dir.pwd
210212
q = Thread::Queue.new
211213
t = Thread.new do
@@ -282,7 +284,7 @@ def test_glob
282284
end
283285

284286
def test_glob_recursive
285-
omit "not ractor safe" unless main_ractor?
287+
omit "Dir.chdir" unless main_ractor?
286288
bug6977 = '[ruby-core:47418]'
287289
bug8006 = '[ruby-core:53108] [Bug #8006]'
288290
Dir.chdir(@root) do
@@ -312,7 +314,7 @@ def test_glob_recursive
312314
end
313315

314316
def test_glob_recursive_directory
315-
omit "not ractor safe" unless main_ractor?
317+
omit "Dir.chdir" unless main_ractor?
316318
Dir.chdir(@root) do
317319
['d', 'e'].each do |path|
318320
FileUtils.mkdir_p("c/#{path}/a/b/c")
@@ -330,7 +332,7 @@ def test_glob_recursive_directory
330332
end
331333

332334
def test_glob_starts_with_brace
333-
omit "not ractor safe" unless main_ractor?
335+
omit "Dir.chdir" unless main_ractor?
334336
Dir.chdir(@root) do
335337
bug15649 = '[ruby-core:91728] [Bug #15649]'
336338
assert_equal(["#{@root}/a", "#{@root}/b"],
@@ -339,7 +341,7 @@ def test_glob_starts_with_brace
339341
end
340342

341343
def test_glob_recursive_with_brace
342-
omit "not ractor safe" unless main_ractor?
344+
omit "Dir.chdir" unless main_ractor?
343345
Dir.chdir(@root) do
344346
bug19042 = '[ruby-core:110220] [Bug #19042]'
345347
%w"c/dir_a c/dir_b c/dir_b/dir".each do |d|
@@ -354,7 +356,7 @@ def test_glob_recursive_with_brace
354356
end
355357

356358
def test_glob_order
357-
omit "not ractor safe" unless main_ractor?
359+
omit "Dir.chdir" unless main_ractor?
358360
Dir.chdir(@root) do
359361
assert_equal(["#{@root}/a", "#{@root}/b"], Dir.glob("#{@root}/[ba]"))
360362
assert_equal(["#{@root}/b", "#{@root}/a"], Dir.glob(%W"#{@root}/b #{@root}/a"))
@@ -384,7 +386,7 @@ def test_glob_too_may_open_files
384386
end
385387

386388
def test_glob_base
387-
omit "not ractor safe (Dir.chdir)" unless main_ractor?
389+
omit "Dir.chdir" unless main_ractor?
388390
files = %w[a/foo.c c/bar.c]
389391
files.each {|n| File.write(File.join(@root, n), "")}
390392
Dir.mkdir(File.join(@root, "a/dir"))
@@ -425,7 +427,7 @@ def test_glob_base
425427
end
426428

427429
def test_glob_base_dir
428-
omit "not ractor safe" unless main_ractor?
430+
omit "Dir.chdir" unless main_ractor?
429431
files = %w[a/foo.c c/bar.c]
430432
files.each {|n| File.write(File.join(@root, n), "")}
431433
Dir.mkdir(File.join(@root, "a/dir"))
@@ -448,7 +450,7 @@ def test_glob_base_dir
448450
end
449451

450452
def test_glob_ignore_casefold_invalid_encoding
451-
omit "not ractor safe" unless main_ractor?
453+
omit "Dir.chdir" unless main_ractor?
452454
bug14456 = "[ruby-core:85448]"
453455
filename = "\u00AAa123".encode('ISO-8859-1')
454456
File.write(File.join(@root, filename), "")
@@ -566,7 +568,7 @@ def test_glob_metachar
566568
end
567569

568570
def test_glob_cases
569-
omit "not ractor safe (Dir.chdir)" unless main_ractor?
571+
omit "Dir.chdir" unless main_ractor?
570572
feature5994 = "[ruby-core:42469] [Feature #5994]"
571573
feature5994 << "\nDir.glob should return the filename with actual cases on the filesystem"
572574
Dir.chdir(File.join(@root, "a")) do
@@ -732,7 +734,7 @@ def test_fileno
732734
end
733735

734736
def test_for_fd
735-
omit "not ractor safe" unless main_ractor?
737+
omit "Dir.chdir" unless main_ractor?
736738
if Dir.respond_to? :for_fd
737739
begin
738740
new_dir = Dir.new('..')

test/ruby/test_gc.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ def test_measure_total_time
323323

324324
def test_latest_gc_info
325325
omit 'stress' if GC.stress
326+
omit "GC.stress=" if multiple_ractors?
326327

327328
assert_separately([], __FILE__, __LINE__, <<-'RUBY')
328329
GC.start
@@ -342,10 +343,12 @@ def test_latest_gc_info
342343
assert_equal true, h[:immediate_sweep]
343344
assert_equal true, h.key?(:need_major_by)
344345

345-
GC.stress = true
346-
assert_equal :force, GC.latest_gc_info[:major_by]
347-
ensure
348-
GC.stress = false
346+
begin
347+
GC.stress = true
348+
assert_equal :force, GC.latest_gc_info[:major_by]
349+
ensure
350+
GC.stress = false
351+
end
349352
end
350353

351354
def test_latest_gc_info_argument
@@ -904,7 +907,7 @@ def test_ast_node_buffer
904907
end
905908

906909
def test_old_to_young_reference
907-
pend "ObjectSpace.dump not yet ractor safe" if non_main_ractor?
910+
pend "ObjectSpace.dump not yet ractor safe" unless main_ractor?
908911
EnvUtil.without_gc do
909912
require "objspace"
910913

test/ruby/test_hash.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,6 +2265,7 @@ def test_label_syntax
22652265
end
22662266

22672267
def test_broken_hash_value
2268+
omit "too many objects" if multiple_ractors?
22682269
bug14218 = '[ruby-core:84395] [Bug #14218]'
22692270

22702271
assert_equal(0, 1_000_000.times.count{a=Object.new.hash; b=Object.new.hash; a < 0 && b < 0 && a + b > 0}, bug14218)

test/ruby/test_integer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class TestInteger < Test::Unit::TestCase
77
LONG_MAX = RbConfig::LIMITS['LONG_MAX']
88

99
def test_aref
10-
10+
pend "TODO: why taking too long" if multiple_ractors?
1111
[
1212
*-16..16,
1313
*(FIXNUM_MIN-2)..(FIXNUM_MIN+2),

test/ruby/test_io.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,7 @@ def test_close_write_non_readable
18601860
end
18611861

18621862
def test_close_read_write_separately
1863+
pend "TODO: buggy with ractors" if multiple_ractors?
18631864
bug = '[ruby-list:49598]'
18641865
(1..10).each do |i|
18651866
assert_nothing_raised(IOError, "#{bug} trying ##{i}") do
@@ -2529,6 +2530,7 @@ def try_fdopen(fd, autoclose = true, level = 50)
25292530
end
25302531

25312532
def test_autoclose
2533+
pend "TODO: assert_raise fails sometimes under multiple ractors" if multiple_ractors?
25322534
feature2250 = '[ruby-core:26222]'
25332535
pre = 'ft2250'
25342536

@@ -2615,6 +2617,7 @@ def o.to_open(kw); kw; end
26152617
end
26162618

26172619
def test_open_pipe
2620+
omit "fork" unless main_ractor?
26182621
assert_deprecated_warning(/Kernel#open with a leading '\|'/) do # https://bugs.ruby-lang.org/issues/19630
26192622
open("|" + EnvUtil.rubybin, "r+") do |f|
26202623
f.puts "puts 'foo'"
@@ -3993,6 +3996,7 @@ def test_sysread_unlocktmp_ensure
39933996
end if /cygwin/ !~ RUBY_PLATFORM
39943997

39953998
def test_exception_at_close
3999+
pend "TODO: assert_raise fails sometimes under multiple ractors" if multiple_ractors?
39964000
bug10153 = '[ruby-core:64463] [Bug #10153] exception in close at the end of block'
39974001
assert_raise(Errno::EBADF, bug10153) do
39984002
IO.pipe do |r, w|
@@ -4472,4 +4476,18 @@ def test_fork_close
44724476
assert_predicate(status, :success?)
44734477
RUBY
44744478
end
4479+
4480+
def test_no_fork_in_ractor
4481+
omit "fork is not supported" unless Process.respond_to?(:fork)
4482+
4483+
assert_ractor(<<~'RUBY')
4484+
r = Ractor.new do
4485+
fork { }
4486+
end
4487+
end
4488+
assert_raise Ractor::IsolationError do
4489+
r.value
4490+
end
4491+
RUBY
4492+
end
44754493
end

0 commit comments

Comments
 (0)