about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-03-18 08:07:26 +0000
committerEric Wong <e@80x24.org>2017-03-18 08:10:52 +0000
commit958d445f48ceb1b6ded4f193d03681273734c860 (patch)
treea44b656d7f3428c9f80804bdfbb161394b31d8dc
parentcef65a3fb602b9a9f3348cf622a3c9215783aabf (diff)
downloadruby_posix_mq-958d445f48ceb1b6ded4f193d03681273734c860.tar.gz
Apparently POSIX message queues adopted close-on-fork behavior
in FreeBSD at some point.  Oh well, somebody else who is more
interested in FreeBSD than can look into fixing it on their end.

Improve exception reporting a bit while we're at it.
-rw-r--r--test/test_posix_mq.rb25
1 files changed, 20 insertions, 5 deletions
diff --git a/test/test_posix_mq.rb b/test/test_posix_mq.rb
index e831012..843b65e 100644
--- a/test/test_posix_mq.rb
+++ b/test/test_posix_mq.rb
@@ -303,9 +303,10 @@ class Test_POSIX_MQ < Test::Unit::TestCase
       begin
         @mq.notify = :USR1
       rescue Errno::EBUSY
-        exit 0
+        exit!(0)
       rescue => e
-        p e
+        exit!(0) if Errno::EBADF === e && RUBY_PLATFORM =~ /freebsd/
+        warn "#{e.message} (#{e.class})\n"
       end
       exit! 1
     end
@@ -326,14 +327,28 @@ class Test_POSIX_MQ < Test::Unit::TestCase
   end
 
   def test_setattr_fork
+    return if RUBY_PLATFORM !~ /freebsd/
     @mq = POSIX_MQ.new @path, IO::CREAT|IO::WRONLY, 0666
     mq_attr = POSIX_MQ::Attr.new(IO::NONBLOCK)
     @mq.attr = mq_attr
     assert @mq.nonblock?
 
-    pid = fork { @mq.nonblock = false }
-    assert Process.waitpid2(pid)[1].success?
-    assert ! @mq.nonblock?
+    pid = fork do
+      begin
+        @mq.nonblock = false
+      rescue => e
+        exit!(2) if Errno::EBADF === e && RUBY_PLATFORM =~ /freebsd/
+        warn "#{e.message} (#{e.class})\n"
+        exit!(1)
+      end
+      exit!(0)
+    end
+    _, status = Process.waitpid2(pid)
+    if status.success?
+      assert ! @mq.nonblock?
+    else
+      assert_equal 2, status.exitstatus
+    end
   end
 
   def test_new_nonblocking