1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
eregon 2017-11-19 15:15:31 +00:00
parent b693cdf159
commit bd69f8e11c
2 changed files with 50 additions and 0 deletions

View file

@ -448,6 +448,56 @@ describe "Module#autoload" do
end end
end 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 end
it "loads the registered constant even if the constant was already loaded by another thread" do it "loads the registered constant even if the constant was already loaded by another thread" do