ruby-changes:46845
From: nobu <ko1@a...>
Date: Tue, 30 May 2017 00:34:51 +0900 (JST)
Subject: [ruby-changes:46845] nobu:r58959 (trunk): Run in separate process/pgrp [Bug #13609]
nobu 2017-05-30 00:34:45 +0900 (Tue, 30 May 2017) New Revision: 58959 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58959 Log: Run in separate process/pgrp [Bug #13609] Modified files: trunk/spec/rubyspec/core/process/setpriority_spec.rb Index: spec/rubyspec/core/process/setpriority_spec.rb =================================================================== --- spec/rubyspec/core/process/setpriority_spec.rb (revision 58958) +++ spec/rubyspec/core/process/setpriority_spec.rb (revision 58959) @@ -4,18 +4,20 @@ describe "Process.setpriority" do https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/core/process/setpriority_spec.rb#L4 # Needs a valid version written for Linux platform_is :darwin do it "sets the scheduling priority for a specified process" do - p = Process.getpriority(Process::PRIO_PROCESS, 0) - Process.setpriority(mock_int(Process::PRIO_PROCESS), - mock_int(0), - mock_int(p + 1)).should == 0 - Process.getpriority(Process::PRIO_PROCESS, 0).should == (p + 1) - if Process.uid == 0 - Process.setpriority(Process::PRIO_PROCESS, 0, p).should == 0 - else - lambda { - Process.setpriority(Process::PRIO_PROCESS, 0, p) - }.should raise_error(Errno::EACCES) + priority = Process.getpriority(Process::PRIO_PROCESS, 0) + IO.popen('-') do |f| + if f + pr = Integer(f.gets) + Integer(f.gets).should == 0 + Integer(f.gets).should == (pr+1) + else + pr = Process.getpriority(Process::PRIO_PROCESS, 0) + p pr + p Process.setpriority(Process::PRIO_PROCESS, 0, (pr + 1)) + p Process.getpriority(Process::PRIO_PROCESS, 0) + end end + Process.getpriority(Process::PRIO_PROCESS, 0).should == priority end end @@ -23,26 +25,21 @@ describe "Process.setpriority" do https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/core/process/setpriority_spec.rb#L25 # whack with either permission errors or just the wrong value platform_is_not :darwin, :freebsd, :windows do it "sets the scheduling priority for a specified process group" do - pr = Process.getpriority(Process::PRIO_PGRP, 0) - - Process.setpriority(Process::PRIO_PGRP, 0, pr + 1).should == 0 - Process.getpriority(Process::PRIO_PGRP, 0).should == (pr + 1) - if Process.uid == 0 - Process.setpriority(Process::PRIO_PGRP, 0, pr).should == 0 - else - # EACCESS is not always raised. It's a stupid OS behavior. - ok = false - begin - Process.setpriority(Process::PRIO_PGRP, 0, pr) - ok = true - rescue Errno::EACCES - ok = true - rescue Object - ok = false + priority = Process.getpriority(Process::PRIO_PGRP, 0) + IO.popen('-') do |f| + if f + pr = Integer(f.gets) + Integer(f.gets).should == 0 + Integer(f.gets).should == (pr+1) + else + Process.setpgrp + pr = Process.getpriority(Process::PRIO_PGRP, 0) + p pr + p Process.setpriority(Process::PRIO_PGRP, 0, pr + 1) + p Process.getpriority(Process::PRIO_PGRP, 0) end - - ok.should == true end + Process.getpriority(Process::PRIO_PGRP, 0).should == priority end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/