diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-29 15:34:45 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-29 15:34:45 +0000 |
commit | 252cffcafbda48355a1a07d4541e4817a345a5ab (patch) | |
tree | 00cb397a99bde0970835a1842d8d3a085b87f05a /spec | |
parent | 3028ac24103cbee81d41bafaf736fe77a1b1dc84 (diff) | |
download | ruby-252cffcafbda48355a1a07d4541e4817a345a5ab.tar.gz |
Run in separate process/pgrp [Bug #13609]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58959 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec')
-rw-r--r-- | spec/rubyspec/core/process/setpriority_spec.rb | 55 |
1 files changed, 26 insertions, 29 deletions
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 |