Actions
Bug #11683
closedmulti-threaded autoload and defined? sometimes fails
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.0dev (2015-11-13 trunk 52552) [x86_64-linux]
Description
I get the following failure. This is a multi-threaded autoload and defined? method test.
If I add wait queue code introduced at r52332 to rb_const_defined_0
function, the test is not failed.
I attached the patch.
diff --git a/test/ruby/test_autoload.rb b/test/ruby/test_autoload.rb
index a672e0b..c71668e 100644
--- a/test/ruby/test_autoload.rb
+++ b/test/ruby/test_autoload.rb
@@ -234,6 +234,28 @@ p Foo::Bar
end
end
+ def test_defined_with_autoload
+ ruby_impl_require do |called_with|
+ Tempfile.create(%w(autoload .rb)) do |file|
+ file.puts "class AutoloadTest; module B; end; end"
+ file.flush
+ add_autoload(file.path)
+ begin
+ thrs = []
+ 2.times do
+ thrs << Thread.new do
+ Thread.pass; assert_equal("constant", defined? Object::AutoloadTest::B)
+ end
+ end
+ thrs.each(&:join)
+ ensure
+ remove_autoload_constant
+ end
+ assert_equal [file.path], called_with.uniq
+ end
+ end
+ end
+
def add_autoload(path)
(@autoload_paths ||= []) << path
::Object.class_eval {autoload(:AutoloadTest, path)}
$ while [ $? -eq 0 ]; do make test-all TESTS="-v ruby/test_autoload.rb -n test_defined_with_autoload"; done
(snip)
1) Failure:
TestAutoload#test_defined_with_autoload [/home/shirosaki/src/ruby/test/ruby/test_autoload.rb:247]:
<"constant"> expected but was
<nil>.
Files
Updated by nobu (Nobuyoshi Nakada) almost 9 years ago
- Description updated (diff)
I could reproduce it by iterating 10 times from add_autoload
through ensure
block.
Updated by h.shirosaki (Hiroshi Shirosaki) almost 9 years ago
If I add sleep 0.01
in threads, the test more likely to fail on my Ubuntu 15.10 machine.
require 'tempfile'
Tempfile.create(%w(autoload .rb)) do |file|
file.puts "class AutoloadTest; module B; end; end"
file.flush
autoload(:AutoloadTest, file.path)
begin
thrs = []
2.times do
thrs << Thread.new do
Thread.pass
sleep 0.01
unless "constant" == defined?(Object::AutoloadTest::B)
raise "defined? Object::AutoloadTest::B is not constant!"
end
end
end
thrs.each(&:join)
end
end
Updated by jeremyevans0 (Jeremy Evans) over 5 years ago
- Related to Bug #11384: multi-threaded autoload sometimes fails added
Updated by jeremyevans0 (Jeremy Evans) over 5 years ago
- Status changed from Open to Closed
Actions
Like0
Like0Like0Like0Like0