From 4fbb9aa3cb6c31ec128bfb31f59efa66d66adba4 Mon Sep 17 00:00:00 2001 From: eregon Date: Sat, 28 Apr 2018 19:50:06 +0000 Subject: Update to ruby/spec@6f38a82 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- spec/ruby/core/module/autoload_spec.rb | 77 +++++++++++++++++----------------- 1 file changed, 38 insertions(+), 39 deletions(-) (limited to 'spec/ruby/core/module/autoload_spec.rb') diff --git a/spec/ruby/core/module/autoload_spec.rb b/spec/ruby/core/module/autoload_spec.rb index f375ac2450..f355a5968d 100644 --- a/spec/ruby/core/module/autoload_spec.rb +++ b/spec/ruby/core/module/autoload_spec.rb @@ -400,52 +400,51 @@ describe "Module#autoload" do ModuleSpecs::Autoload.send(:remove_const, :Concur) end - ruby_bug "#10892", ""..."2.3" do - it "blocks others threads while doing an autoload" do - file_path = fixture(__FILE__, "repeated_concurrent_autoload.rb") - autoload_path = file_path.sub(/\.rb\Z/, '') - mod_count = 30 - thread_count = 16 - - mod_names = [] - mod_count.times do |i| - mod_name = :"Mod#{i}" - Object.autoload mod_name, autoload_path - mod_names << mod_name - end + # https://bugs.ruby-lang.org/issues/10892 + it "blocks others threads while doing an autoload" do + file_path = fixture(__FILE__, "repeated_concurrent_autoload.rb") + autoload_path = file_path.sub(/\.rb\Z/, '') + mod_count = 30 + thread_count = 16 + + mod_names = [] + mod_count.times do |i| + mod_name = :"Mod#{i}" + Object.autoload mod_name, autoload_path + mod_names << mod_name + end + + barrier = ModuleSpecs::CyclicBarrier.new thread_count + ScratchPad.record ModuleSpecs::ThreadSafeCounter.new - barrier = ModuleSpecs::CyclicBarrier.new thread_count - ScratchPad.record ModuleSpecs::ThreadSafeCounter.new - - threads = (1..thread_count).map do - Thread.new do - mod_names.each do |mod_name| - break false unless barrier.enabled? - - was_last_one_in = barrier.await # wait for all threads to finish the iteration - # clean up so we can autoload the same file again - $LOADED_FEATURES.delete(file_path) if was_last_one_in && $LOADED_FEATURES.include?(file_path) - barrier.await # get ready for race - - begin - Object.const_get(mod_name).foo - rescue NoMethodError - barrier.disable! - break false - end + threads = (1..thread_count).map do + Thread.new do + mod_names.each do |mod_name| + break false unless barrier.enabled? + + was_last_one_in = barrier.await # wait for all threads to finish the iteration + # clean up so we can autoload the same file again + $LOADED_FEATURES.delete(file_path) if was_last_one_in && $LOADED_FEATURES.include?(file_path) + barrier.await # get ready for race + + begin + Object.const_get(mod_name).foo + rescue NoMethodError + barrier.disable! + break false end end end + end - # check that no thread got a NoMethodError because of partially loaded module - threads.all? {|t| t.value}.should be_true + # check that no thread got a NoMethodError because of partially loaded module + threads.all? {|t| t.value}.should be_true - # check that the autoloaded file was evaled exactly once - ScratchPad.recorded.get.should == mod_count + # check that the autoloaded file was evaled exactly once + ScratchPad.recorded.get.should == mod_count - mod_names.each do |mod_name| - Object.send(:remove_const, mod_name) - end + mod_names.each do |mod_name| + Object.send(:remove_const, mod_name) end end -- cgit v1.2.3