about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-01-09 07:01:42 +0000
committerEric Wong <e@80x24.org>2023-01-09 07:02:27 +0000
commit0de44f7bc1e6cc873ac24c57c4ce62c0759194c5 (patch)
tree885151a1ebc535f5300c4682a90e1bce7f79e977
parente8eb1187f958179482ebc0efd2d51719f44cc8a0 (diff)
downloadmwrap-0de44f7bc1e6cc873ac24c57c4ce62c0759194c5.tar.gz
`p' will deadlock even with `STDOUT.sync=true', apparently :<
-rw-r--r--test/test_mwrap.rb34
1 files changed, 21 insertions, 13 deletions
diff --git a/test/test_mwrap.rb b/test/test_mwrap.rb
index e04fab5..58c9743 100644
--- a/test/test_mwrap.rb
+++ b/test/test_mwrap.rb
@@ -126,33 +126,41 @@ class TestMwrap < Test::Unit::TestCase
 
   # some URCU flavors use USR1, ensure the one we choose does not
   def test_sigusr1_works
+    err = Tempfile.new('dump')
     cmd = @@cmd + %w(
       -e STDOUT.sync=true
-      -e trap(:USR1){p("HELLO_WORLD")}
+      -e trap(:USR1){STDOUT.syswrite("HELLO_WORLD\n")}
       -e END{Mwrap.dump}
-      -e puts -e STDIN.read)
+      -e puts("HI")
+      -e STDIN.read)
     IO.pipe do |r, w|
       IO.pipe do |r2, w2|
-        pid = spawn(@@env, *cmd, in: r2, out: w, err: '/dev/null')
+        pid = spawn(@@env, *cmd, in: r2, out: w, err: err)
         r2.close
         w.close
-        assert_equal "\n", r.gets
+        assert_equal "HI\n", r.gets, '#puts HI fired'
         buf = +''
         10.times { Process.kill(:USR1, pid) }
-        while r.wait_readable(0.1)
+        Thread.pass # sched_yield
+        while r.wait_readable(0.5)
           case tmp = r.read_nonblock(1000, exception: false)
-          when String
-            buf << tmp
-          when nil
-            break
+          when String; buf << tmp; break
+          when nil; break
+          else
+            warn "Unexpected read_nonblock result: #{tmp.inspect}"
           end
         end
-        w2.close
-        Process.wait(pid)
-        assert_predicate $?, :success?, $?.inspect
-        assert_equal(["\"HELLO_WORLD\"\n"], buf.split(/^/).uniq)
+        w2.close # break from STDERR.read
+        _, st = Process.wait2(pid)
+        warn "# buf=#{buf.inspect}" if $DEBUG
+        assert_predicate(st, :success?,
+          "#{st.inspect} is success buf=#{buf.inspect} "\
+          "err=#{err.rewind;err.read.inspect}")
+        assert_equal(["HELLO_WORLD\n"], buf.split(/^/).uniq)
       end
     end
+  ensure
+    err.close! if err
   end
 
   def test_reset