diff options
author | Koichi Sasada <ko1@atdot.net> | 2023-03-05 02:42:38 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2023-03-06 13:30:54 +0900 |
commit | 883871d722374b11b0bdd293a027609e8b891ba9 (patch) | |
tree | 8d335080039718774e80a3ecc6bada14cc9cd514 /bootstraptest | |
parent | f70b46dbc70a2367525e7124f50d924d06261888 (diff) | |
download | ruby-883871d722374b11b0bdd293a027609e8b891ba9.tar.gz |
add a test for Ractor
Ractor should take care method cache invalidation.
Added test will miss method cache on each method call.
Diffstat (limited to 'bootstraptest')
-rw-r--r-- | bootstraptest/test_ractor.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb index 122994e555..831bca1239 100644 --- a/bootstraptest/test_ractor.rb +++ b/bootstraptest/test_ractor.rb @@ -1570,6 +1570,7 @@ assert_equal "ok", %q{ end } +# check method cache invalidation assert_equal "ok", %q{ module M def foo @@ -1609,6 +1610,33 @@ assert_equal "ok", %q{ "ok" } +# check method cache invalidation +assert_equal 'true', %q{ + class C1; def self.foo = 1; end + class C2; def self.foo = 2; end + class C3; def self.foo = 3; end + class C4; def self.foo = 5; end + class C5; def self.foo = 7; end + class C6; def self.foo = 11; end + class C7; def self.foo = 13; end + class C8; def self.foo = 17; end + + LN = 10_000 + RN = 10 + CS = [C1, C2, C3, C4, C5, C6, C7, C8] + rs = RN.times.map{|i| + Ractor.new(CS.shuffle){|cs| + LN.times.sum{ + cs.inject(1){|r, c| r * c.foo} # c.foo invalidates method cache entry + } + } + } + + n = CS.inject(1){|r, c| r * c.foo} * LN + rs.map{|r| r.take} == Array.new(RN){n} +} + +# check experimental warning assert_match /\Atest_ractor\.rb:1:\s+warning:\s+Ractor is experimental/, %q{ Warning[:experimental] = $VERBOSE = true STDERR.reopen(STDOUT) |