summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-09-19 00:26:49 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-09-19 15:34:16 +0900
commit1c9381283e68b9021df2509fb64d663998d8cb5a (patch)
tree086277d5270f7c54f414abbf5bc35ebbbf6c78d6 /test
parent7cab7e5fde150bdef955ba4182d26f84e1c5d122 (diff)
Add another test for `Process.daemon`
Check for that the daemon process is detached, that means it is not a child and not waitable.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6402
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_process.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb
index c4888598a8..6340f622fc 100644
--- a/test/ruby/test_process.rb
+++ b/test/ruby/test_process.rb
@@ -1876,6 +1876,26 @@ class TestProcess < Test::Unit::TestCase
assert_not_equal(cpid, dpid)
end
+ def test_daemon_detached
+ IO.popen("-", "r+") do |f|
+ if f
+ assert_equal(f.pid, Process.wait(f.pid))
+
+ dpid, ppid = Integer(f.gets), Integer(f.gets)
+
+ message = "daemon #{dpid} should be detached"
+ assert_not_equal($$, ppid, message) # would be 1 almost always
+ assert_raise(Errno::ECHILD, message) {Process.wait(dpid)}
+ assert_kind_of(Integer, Process.kill(0, dpid), message)
+
+ break # close f, and let the daemon resume and exit
+ end
+ Process.daemon(false, true)
+ puts $$, Process.ppid
+ $stdin.gets # wait for the above assertions using signals
+ end
+ end
+
if File.directory?("/proc/self/task") && /netbsd[a-z]*[1-6]/ !~ RUBY_PLATFORM
def test_daemon_no_threads
pid, data = IO.popen("-", "r+") do |f|