summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-29 15:34:45 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-29 15:34:45 +0000
commiteee4dee0a2c889d152ebd7eb56ec2f75a4f85d76 (patch)
tree00cb397a99bde0970835a1842d8d3a085b87f05a /spec
parent01ebc04fa242eaa9ea6129e69a37570e92360056 (diff)
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.rb55
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