* [PATCH] test/ruby/test_process.rb: test thread+sigs work after failed exec
@ 2015-07-18 1:24 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-07-18 1:24 UTC (permalink / raw)
To: spew
Preparation for possible upcoming changes to timer thread. We need
to ensure signal handling and thread scheduling works after an exec
failure.
---
test/ruby/test_process.rb | 70 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 70 insertions(+)
diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb
index 00bbf9e..80dc344 100644
--- a/test/ruby/test_process.rb
+++ b/test/ruby/test_process.rb
@@ -2092,4 +2092,74 @@ EOS
end
}
end
+
+ def test_signals_work_after_exec_fail
+ r, w = IO.pipe
+ pid = status = nil
+ Timeout.timeout(30) do
+ pid = fork do
+ r.close
+ begin
+ trap(:USR1) { w.syswrite("USR1\n"); exit 0 }
+ exec "/path/to/non/existent/#$$/#{rand}.ex"
+ rescue SystemCallError
+ w.syswrite("exec failed\n")
+ end
+ sleep
+ exit 1
+ end
+ w.close
+ assert_equal "exec failed\n", r.gets
+ Process.kill(:USR1, pid)
+ assert_equal "USR1\n", r.gets
+ assert_nil r.gets
+ _, status = Process.waitpid2(pid)
+ end
+ assert_predicate status, :success?
+ rescue Timeout::Error
+ begin
+ Process.kill(:KILL, pid)
+ rescue Errno::ESRCH
+ end
+ raise
+ ensure
+ w.close if w
+ r.close if r
+ end if defined?(fork)
+
+ def test_threading_works_after_exec_fail
+ r, w = IO.pipe
+ pid = status = nil
+ Timeout.timeout(30) do
+ pid = fork do
+ r.close
+ begin
+ exec "/path/to/non/existent/#$$/#{rand}.ex"
+ rescue SystemCallError
+ w.syswrite("exec failed\n")
+ end
+ run = true
+ th1 = Thread.new { i = 0; i += 1 while run; i }
+ th2 = Thread.new { j = 0; j += 1 while run && Thread.pass.nil?; j }
+ sleep 0.5
+ run = false
+ w.syswrite "#{th1.value} #{th2.value}\n"
+ end
+ w.close
+ assert_equal "exec failed\n", r.gets
+ vals = r.gets.chomp.split.map!(&:to_i)
+ assert_operator vals[0], :>, vals[1], vals.inspect
+ _, status = Process.waitpid2(pid)
+ end
+ assert_predicate status, :success?
+ rescue Timeout::Error
+ begin
+ Process.kill(:KILL, pid)
+ rescue Errno::ESRCH
+ end
+ raise
+ ensure
+ w.close if w
+ r.close if r
+ end if defined?(fork)
end
--
EW
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2015-07-18 1:24 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-18 1:24 [PATCH] test/ruby/test_process.rb: test thread+sigs work after failed exec Eric Wong
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).