Skip to content

Commit 250c999

Browse files
committed
Change test-all suite to enable testing each test in a separate ractor.
This tests for ractor safety issues as well as issues with GC and the ractor scheduler. It also tests move/copy logic because it uses these internally for running the tests. You can enable these tests with RUBY_TESTS_WITH_RACTORS=1 when running `make test-all TESTS=test/ruby`. These ractor tests are currently only working for tests under the "test/ruby" directory, so don't run any others with this ENV var set or you will get errors. Currently there are GC issues with ractors so in tool/lib/test/unit.rb, I disable the GC before running any of the tests (for now). If you uncomment this, you will get errors and you can debug the GC issues.
1 parent c5c894c commit 250c999

101 files changed

Lines changed: 1224 additions & 611 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ext/-test-/file/fs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ get_noatime_p(VALUE self, VALUE str)
105105
void
106106
Init_fs(VALUE module)
107107
{
108+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
109+
rb_ext_ractor_safe(true);
110+
#endif
108111
VALUE fs = rb_define_module_under(module, "Fs");
109112
rb_define_module_function(fs, "fsname", get_fsname, 1);
110113
rb_define_module_function(fs, "noatime?", get_noatime_p, 1);

ext/-test-/integer/init.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
void
66
Init_integer(void)
77
{
8+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
9+
rb_ext_ractor_safe(true);
10+
#endif
811
VALUE mBug = rb_define_module("Bug");
912
VALUE klass = rb_define_class_under(mBug, "Integer", rb_cObject);
1013
TEST_INIT_FUNCS(init);

ext/-test-/iter/break.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ iter_break_value(VALUE self, VALUE val)
1919
void
2020
Init_break(VALUE klass)
2121
{
22+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
23+
// Mark this extension as Ractor-safe.
24+
rb_ext_ractor_safe(true);
25+
#endif
2226
VALUE breakable = rb_define_module_under(klass, "Breakable");
2327
rb_define_module_function(breakable, "iter_break", iter_break, 0);
2428
rb_define_module_function(breakable, "iter_break_value", iter_break_value, 1);

ext/-test-/iter/init.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
void
66
Init_iter(void)
77
{
8+
9+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
10+
// Mark this extension as Ractor-safe.
11+
rb_ext_ractor_safe(true);
12+
#endif
813
VALUE mBug = rb_define_module("Bug");
914
VALUE klass = rb_define_module_under(mBug, "Iter");
1015
TEST_INIT_FUNCS(init);

ext/-test-/iter/yield.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ yield_block(int argc, VALUE *argv, VALUE self)
1010
void
1111
Init_yield(VALUE klass)
1212
{
13+
14+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
15+
// Mark this extension as Ractor-safe.
16+
rb_ext_ractor_safe(true);
17+
#endif
1318
VALUE yield = rb_define_module_under(klass, "Yield");
1419

1520
rb_define_method(yield, "yield_block", yield_block, -1);

ext/-test-/rb_call_super_kw/rb_call_super_kw.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ rb_call_super_kw_m(int argc, VALUE *argv, VALUE self)
99
void
1010
Init_rb_call_super_kw(void)
1111
{
12+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
13+
// Mark this extension as Ractor-safe.
14+
rb_ext_ractor_safe(true);
15+
#endif
1216
VALUE module = rb_define_module("Bug");
1317
module = rb_define_module_under(module, "RbCallSuperKw");
1418
rb_define_method(module, "m", rb_call_super_kw_m, -1);

test/fileutils/test_fileutils.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,10 @@ def check_have_hardlink?
8484
return true
8585
end
8686

87-
@@no_broken_symlink = false
88-
if /cygwin/ =~ RUBY_PLATFORM and /\bwinsymlinks:native(?:strict)?\b/ =~ ENV["CYGWIN"]
89-
@@no_broken_symlink = true
90-
end
87+
NO_BROKEN_SYMLINK = /cygwin/ =~ RUBY_PLATFORM and /\bwinsymlinks:native(?:strict)?\b/ =~ ENV["CYGWIN"]
9188

9289
def no_broken_symlink?
93-
@@no_broken_symlink
90+
NO_BROKEN_SYMLINK
9491
end
9592

9693
def has_capsh?
@@ -196,7 +193,7 @@ def teardown
196193
end
197194

198195

199-
TARGETS = %w( data/a data/all data/random data/zero )
196+
TARGETS = %w( data/a data/all data/random data/zero ).freeze
200197

201198
def prepare_data_file
202199
File.open('data/a', 'w') {|f|

test/ruby/enc/test_case_comprehensive.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
class TestComprehensiveCaseMapping < Test::Unit::TestCase
77
UNICODE_VERSION = RbConfig::CONFIG['UNICODE_VERSION']
8-
path = File.expand_path("../../../enc/unicode/data/#{UNICODE_VERSION}", __dir__)
9-
UNICODE_DATA_PATH = File.directory?("#{path}/ucd") ? "#{path}/ucd" : path
8+
path = File.expand_path("../../../enc/unicode/data/#{UNICODE_VERSION}", __dir__).freeze
9+
UNICODE_DATA_PATH = File.directory?("#{path}/ucd") ? "#{path}/ucd".freeze : path
1010

1111
def self.hex2utf8(s)
1212
s.split(' ').map { |c| c.to_i(16) }.pack('U*')
@@ -29,7 +29,7 @@ def test_data_files_available
2929
end
3030
end
3131

32-
TestComprehensiveCaseMapping.data_files_available? and class TestComprehensiveCaseMapping
32+
TestComprehensiveCaseMapping.data_files_available? && will_run_in_main_ractor? && class TestComprehensiveCaseMapping
3333
(CaseTest = Struct.new(:method_name, :attributes, :first_data, :follow_data)).class_eval do
3434
def initialize(method_name, attributes, first_data, follow_data=first_data)
3535
super

test/ruby/enc/test_emoji_breaks.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,16 @@ def self.files
4646
end
4747

4848
UNICODE_VERSION = RbConfig::CONFIG['UNICODE_VERSION']
49-
UNICODE_DATA_PATH = File.expand_path("../../../enc/unicode/data/#{UNICODE_VERSION}/ucd/emoji", __dir__)
49+
UNICODE_DATA_PATH = File.expand_path("../../../enc/unicode/data/#{UNICODE_VERSION}/ucd/emoji", __dir__).freeze
5050
EMOJI_VERSION = RbConfig::CONFIG['UNICODE_EMOJI_VERSION']
51-
EMOJI_DATA_PATH = File.expand_path("../../../enc/unicode/data/emoji/#{EMOJI_VERSION}", __dir__)
51+
EMOJI_DATA_PATH = File.expand_path("../../../enc/unicode/data/emoji/#{EMOJI_VERSION}", __dir__).freeze
5252

5353
EMOJI_DATA_FILES = %w[emoji-sequences emoji-test emoji-zwj-sequences].map do |basename|
5454
BreakFile.new(basename, EMOJI_DATA_PATH, EMOJI_VERSION)
5555
end
5656
UNICODE_DATA_FILE = BreakFile.new('emoji-variation-sequences', UNICODE_DATA_PATH, UNICODE_VERSION)
5757
EMOJI_DATA_FILES << UNICODE_DATA_FILE
58+
Ractor.make_shareable(EMOJI_DATA_FILES)
5859

5960
def self.data_files_available?
6061
EMOJI_DATA_FILES.all? do |f|

test/ruby/enc/test_grapheme_breaks.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ def initialize(line_number, data, comment)
2727
end
2828

2929
UNICODE_VERSION = RbConfig::CONFIG['UNICODE_VERSION']
30-
path = File.expand_path("../../../enc/unicode/data/#{UNICODE_VERSION}", __dir__)
31-
UNICODE_DATA_PATH = File.directory?("#{path}/ucd/auxiliary") ? "#{path}/ucd/auxiliary" : path
32-
GRAPHEME_BREAK_TEST_FILE = File.expand_path("#{UNICODE_DATA_PATH}/GraphemeBreakTest.txt", __dir__)
30+
path = File.expand_path("../../../enc/unicode/data/#{UNICODE_VERSION}", __dir__).freeze
31+
UNICODE_DATA_PATH = File.directory?("#{path}/ucd/auxiliary") ? "#{path}/ucd/auxiliary".freeze : path
32+
GRAPHEME_BREAK_TEST_FILE = File.expand_path("#{UNICODE_DATA_PATH}/GraphemeBreakTest.txt", __dir__).freeze
3333

3434
def self.file_available?
3535
File.exist? GRAPHEME_BREAK_TEST_FILE
@@ -44,20 +44,22 @@ def test_data_files_available
4444
if file_available?
4545
def read_data
4646
tests = []
47+
lineno = 1
4748
File.foreach(GRAPHEME_BREAK_TEST_FILE, encoding: Encoding::UTF_8) do |line|
48-
if $. == 1 and not line.start_with?("# GraphemeBreakTest-#{UNICODE_VERSION}.txt")
49+
if lineno == 1 and not line.start_with?("# GraphemeBreakTest-#{UNICODE_VERSION}.txt")
4950
raise "File Version Mismatch"
5051
end
52+
lineno += 1
5153
next if /\A#/.match? line
5254
tests << BreakTest.new($., *line.chomp.split('#')) rescue 'whatever'
5355
end
5456
tests
5557
end
5658

5759
def all_tests
58-
@@tests ||= read_data
60+
@grapheme_breaks_tests ||= read_data
5961
rescue Errno::ENOENT
60-
@@tests ||= []
62+
@grapheme_breaks_tests ||= []
6163
end
6264

6365
def test_each_grapheme_cluster

0 commit comments

Comments
 (0)