mwrap user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: <mwrap-public@80x24.org>
Subject: [PATCH] fix test_sigusr1_works
Date: Mon,  9 Jan 2023 07:01:42 +0000	[thread overview]
Message-ID: <20230109070142.10654-1-e@80x24.org> (raw)

`p' will deadlock even with `STDOUT.sync=true', apparently :<
---
 test/test_mwrap.rb | 34 +++++++++++++++++++++-------------
 1 file 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

                 reply	other threads:[~2023-01-09  7:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://80x24.org/mwrap/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230109070142.10654-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=mwrap-public@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mwrap.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).