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

ruby-changes:39208

From: normal <ko1@a...>
Date: Sat, 18 Jul 2015 10:29:51 +0900 (JST)
Subject: [ruby-changes:39208] normal:r51289 (trunk): test/ruby/test_process.rb: test thread+sigs work after failed exec

normal	2015-07-18 10:29:25 +0900 (Sat, 18 Jul 2015)

  New Revision: 51289

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51289

  Log:
    test/ruby/test_process.rb: test thread+sigs work after failed exec
    
    Preparation for possible upcoming changes to timer thread.  We need
    to ensure signal handling and thread scheduling works after an exec
    failure.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_process.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51288)
+++ ChangeLog	(revision 51289)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jul 18 10:29:03 2015  Eric Wong  <e@8...>
+
+	* test/ruby/test_process.rb: test thread+sigs work after failed exec
+
 Sat Jul 18 07:20:18 2015  Jeremy Evans  <code@j...>
 
 	* test/socket/test_nonblock: use smaller buffer for sendmsg
Index: test/ruby/test_process.rb
===================================================================
--- test/ruby/test_process.rb	(revision 51288)
+++ test/ruby/test_process.rb	(revision 51289)
@@ -2092,4 +2092,74 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/ruby/test_process.rb#L2092
       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

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

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