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

ruby-changes:54356

From: mame <ko1@a...>
Date: Wed, 26 Dec 2018 16:02:37 +0900 (JST)
Subject: [ruby-changes:54356] mame:r66570 (trunk): spec/ruby/core/process/setpriority_spec.rb: allow to run under docker

mame	2018-12-26 16:02:31 +0900 (Wed, 26 Dec 2018)

  New Revision: 66570

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

  Log:
    spec/ruby/core/process/setpriority_spec.rb: allow to run under docker
    
    Docker container is not always able to lower the nice value even if the
    euid is a root.  It depends upon the configuration of docker which
    cannot check from the container itself.
    
    This change does check it by actually trying to lower the value first.

  Modified files:
    trunk/spec/ruby/core/process/setpriority_spec.rb
Index: spec/ruby/core/process/setpriority_spec.rb
===================================================================
--- spec/ruby/core/process/setpriority_spec.rb	(revision 66569)
+++ spec/ruby/core/process/setpriority_spec.rb	(revision 66570)
@@ -29,11 +29,26 @@ describe "Process.setpriority" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/process/setpriority_spec.rb#L29
     end
 
     as_superuser do
-      it "sets the scheduling priority for a specified user" do
-        p = Process.getpriority(Process::PRIO_USER, 0)
-        Process.setpriority(Process::PRIO_USER, 0, p + 1).should == 0
-        Process.getpriority(Process::PRIO_USER, 0).should == (p + 1)
-        Process.setpriority(Process::PRIO_USER, 0, p).should == 0
+      p = Process.getpriority(Process::PRIO_USER, 0)
+      # The nice value is a value in the range -20 to 19.
+      # This test tries to change the nice value to +-1, so it cannot run if p == -20 || p == 19.
+      if -20 < p && p < 19
+       begin
+         # Check if we can lower the nice value or not.
+         #
+         # We are not always able to do it even as a root.
+         # Docker container is not always able to do it depending upon the configuration,
+         # which cannot know from the container itself.
+          Process.setpriority(Process::PRIO_USER, 0, p - 1)
+          Process.setpriority(Process::PRIO_USER, 0, p)
+
+          it "sets the scheduling priority for a specified user" do
+            Process.setpriority(Process::PRIO_USER, 0, p + 1).should == 0
+            Process.getpriority(Process::PRIO_USER, 0).should == (p + 1)
+            Process.setpriority(Process::PRIO_USER, 0, p).should == 0
+         end
+       rescue Errno::EACCES
+       end
       end
     end
   end

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

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