[前][次][番号順一覧][スレッド一覧]

ruby-changes:73613

From: Nobuyoshi <ko1@a...>
Date: Mon, 19 Sep 2022 15:34:30 +0900 (JST)
Subject: [ruby-changes:73613] 1c9381283e (master): Add another test for `Process.daemon`

https://git.ruby-lang.org/ruby.git/commit/?id=1c9381283e

From 1c9381283e68b9021df2509fb64d663998d8cb5a Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Mon, 19 Sep 2022 00:26:49 +0900
Subject: Add another test for `Process.daemon`

Check for that the daemon process is detached, that means it is not a
child and not waitable.
---
 test/ruby/test_process.rb | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L1876
       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|
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]