зеркало из https://github.com/github/ruby.git
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:
Родитель
b693cdf159
Коммит
bd69f8e11c
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче