ruby-changes:48735
From: eregon <ko1@a...>
Date: Mon, 20 Nov 2017 00:15:36 +0900 (JST)
Subject: [ruby-changes:48735] eregon:r60851 (trunk): Add specs for concurrent Module#autoload
eregon 2017-11-20 00:15:31 +0900 (Mon, 20 Nov 2017) New Revision: 60851 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60851 Log: Add specs for concurrent Module#autoload * When the file does not exist or the constant is not set. Added files: trunk/spec/ruby/core/module/fixtures/autoload_never_set.rb Modified files: trunk/spec/ruby/core/module/autoload_spec.rb Index: spec/ruby/core/module/autoload_spec.rb =================================================================== --- spec/ruby/core/module/autoload_spec.rb (revision 60850) +++ spec/ruby/core/module/autoload_spec.rb (revision 60851) @@ -448,6 +448,56 @@ describe "Module#autoload" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/module/autoload_spec.rb#L448 end end end + + it "raises a NameError in each thread if the constant is not set" do + file = fixture(__FILE__, "autoload_never_set.rb") + start = false + + threads = Array.new(10) do + Thread.new do + Thread.pass until start + begin + ModuleSpecs::Autoload.autoload :NeverSetConstant, file + Thread.pass + ModuleSpecs::Autoload::NeverSetConstant + rescue NameError => e + e + ensure + Thread.pass + end + end + end + + start = true + threads.each { |t| + t.value.should be_an_instance_of(NameError) + } + end + + it "raises a LoadError in each thread if the file does not exist" do + file = fixture(__FILE__, "autoload_does_not_exist.rb") + start = false + + threads = Array.new(10) do + Thread.new do + Thread.pass until start + begin + ModuleSpecs::Autoload.autoload :FileDoesNotExist, file + Thread.pass + ModuleSpecs::Autoload::FileDoesNotExist + rescue LoadError => e + e + ensure + Thread.pass + end + end + end + + start = true + threads.each { |t| + t.value.should be_an_instance_of(LoadError) + } + end end it "loads the registered constant even if the constant was already loaded by another thread" do Index: spec/ruby/core/module/fixtures/autoload_never_set.rb =================================================================== -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/