diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-11-19 15:15:31 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-11-19 15:15:31 +0000 |
commit | bd69f8e11cf9de4e2bc59cd15ed5090567dca99f (patch) | |
tree | 051e18fa9c4d9b3279752a6f45fa24fc7a4c7a16 /spec | |
parent | b693cdf1592ebc9fc7c8f9bf3fd267f15c66e139 (diff) | |
download | ruby-bd69f8e11cf9de4e2bc59cd15ed5090567dca99f.tar.gz |
Add specs for concurrent Module#autoload
* When the file does not exist or the constant is not set.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60851 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec')
-rw-r--r-- | spec/ruby/core/module/autoload_spec.rb | 50 | ||||
-rw-r--r-- | spec/ruby/core/module/fixtures/autoload_never_set.rb | 0 |
2 files changed, 50 insertions, 0 deletions
diff --git a/spec/ruby/core/module/autoload_spec.rb b/spec/ruby/core/module/autoload_spec.rb index d7b212183b..a72ae7735b 100644 --- a/spec/ruby/core/module/autoload_spec.rb +++ b/spec/ruby/core/module/autoload_spec.rb @@ -448,6 +448,56 @@ describe "Module#autoload" do 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 diff --git a/spec/ruby/core/module/fixtures/autoload_never_set.rb b/spec/ruby/core/module/fixtures/autoload_never_set.rb new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/spec/ruby/core/module/fixtures/autoload_never_set.rb |