* [PATCH] fix test_sigusr1_works
@ 2023-01-09 7:01 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2023-01-09 7:01 UTC (permalink / raw)
To: mwrap-public
`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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2023-01-09 7:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-09 7:01 [PATCH] fix test_sigusr1_works Eric Wong
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).