From eee4dee0a2c889d152ebd7eb56ec2f75a4f85d76 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 29 May 2017 15:34:45 +0000 Subject: Run in separate process/pgrp [Bug #13609] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58959 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- spec/rubyspec/core/process/setpriority_spec.rb | 55 ++++++++++++-------------- 1 file changed, 26 insertions(+), 29 deletions(-) (limited to 'spec/rubyspec') diff --git a/spec/rubyspec/core/process/setpriority_spec.rb b/spec/rubyspec/core/process/setpriority_spec.rb index baccd2244e..69032a9b69 100644 --- a/spec/rubyspec/core/process/setpriority_spec.rb +++ b/spec/rubyspec/core/process/setpriority_spec.rb @@ -4,18 +4,20 @@ describe "Process.setpriority" do # 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 # 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 -- cgit v1.2.3