From bc8687acd62584bf2ba9a951289f3f25a4de7229 Mon Sep 17 00:00:00 2001 From: kosaki Date: Sat, 17 Oct 2015 21:09:10 +0000 Subject: * ruby.c (open_load_file): reset O_NONBLOCK after open. Even if S_ISREG() is true, the file may be file on FUSE filesystem or something. We can't assume O_NONBLOCK is safe. Moreover, we should wait if the path is point to FIFO. That's FIFO semantics. GVL should be transparent from ruby script. Thus, just reopen without O_NONBLOCK for filling the requirements. [Bug #11060][Bug #11559] * ruby.c (loadopen_func): new for the above. * file.c (ruby_is_fd_loadable): new. for checks loadable file type of not. * file.c (rb_file_load_ok): use ruby_is_fd_loadble() * internal.h: add ruby_is_fd_loadble() * common.mk: now, ruby.o depend on thread.h. * test/ruby/test_require.rb (TestRequire#test_loading_fifo_threading_success): new test. This test successful case that loading from FIFO. * test/ruby/test_require.rb (TestRequire#test_loading_fifo_threading_raise): rename from test_loading_fifo_threading. You souldn't rescue an exception if you test raise or not. Moreover, this case should be caught IOError because load(FIFO) should be blocked until given any input. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52151 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_require.rb | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb index d51aeb2ae7..947b285582 100644 --- a/test/ruby/test_require.rb +++ b/test/ruby/test_require.rb @@ -694,7 +694,7 @@ class TestRequire < Test::Unit::TestCase } end - def test_loading_fifo_threading + def test_loading_fifo_threading_raise Tempfile.create(%w'fifo .rb') {|f| f.close File.unlink(f.path) @@ -702,16 +702,39 @@ class TestRequire < Test::Unit::TestCase assert_separately(["-", f.path], <<-END, timeout: 3) th = Thread.current Thread.start {begin sleep(0.001) end until th.stop?; th.raise(IOError)} - assert_nothing_raised do - begin - load(ARGV[0]) - rescue IOError - end + assert_raise(IOError) do + load(ARGV[0]) end END } end unless /mswin|mingw/ =~ RUBY_PLATFORM + def test_loading_fifo_threading_success + Tempfile.create(%w'fifo .rb') {|f| + f.close + File.unlink(f.path) + File.mkfifo(f.path) + + assert_separately(["-", f.path], <<-INPUT, timeout: 3) + path = ARGV[0] + th = Thread.current + Thread.start { + begin + sleep(0.001) + end until th.stop? + open(path, File::WRONLY | File::NONBLOCK) {|fifo_w| + fifo_w.puts "class C1; FOO='foo'; end" + } + } + + load(path) + assert_equal(C1::FOO, "foo") + INPUT + } + + end unless /mswin|mingw/ =~ RUBY_PLATFORM + + def test_throw_while_loading Tempfile.create(%w'bug-11404 .rb') do |f| f.puts 'sleep' -- cgit v1.2.3