diff options
author | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2022-05-17 00:50:02 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-17 00:50:02 +1200 |
commit | f626998c4fa62973cac3a027597f97cdacd0d3c5 (patch) | |
tree | 3aa39f13106415581335eff9d08da60e7eab88a1 /test | |
parent | a7577dbfd3ea53cccf7aaf94208069784ad17791 (diff) |
Delete autoload data from global features after autoload has completed. (#5910)
* Update naming of critical section assertions macros.
* Improved locking for autoload.
Notes
Notes:
Merged-By: ioquatix <samuel@codeotaku.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_autoload.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/ruby/test_autoload.rb b/test/ruby/test_autoload.rb index 7709760d19..afabd5d26b 100644 --- a/test/ruby/test_autoload.rb +++ b/test/ruby/test_autoload.rb @@ -491,4 +491,32 @@ p Foo::Bar ::Object.class_eval {remove_const(:AutoloadTest)} if defined? Object::AutoloadTest TestAutoload.class_eval {remove_const(:AutoloadTest)} if defined? TestAutoload::AutoloadTest end + + def test_autoload_parallel_race + Dir.mktmpdir('autoload') do |tmpdir| + autoload_path = File.join(tmpdir, "autoload_parallel_race.rb") + File.write(autoload_path, 'module Foo; end; module Bar; end') + + assert_separately([], <<-RUBY, timeout: 100) + autoload_path = #{File.realpath(autoload_path).inspect} + + # This should work with no errors or failures. + 1000.times do + autoload :Foo, autoload_path + autoload :Bar, autoload_path + + t1 = Thread.new {Foo} + t2 = Thread.new {Bar} + + t1.join + t2.join + + Object.send(:remove_const, :Foo) + Object.send(:remove_const, :Bar) + + $LOADED_FEATURES.delete(autoload_path) + end + RUBY + end + end end |