summaryrefslogtreecommitdiff
path: root/spec/rubyspec/core/process/setpriority_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/rubyspec/core/process/setpriority_spec.rb')
-rw-r--r--spec/rubyspec/core/process/setpriority_spec.rb60
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/rubyspec/core/process/setpriority_spec.rb b/spec/rubyspec/core/process/setpriority_spec.rb
new file mode 100644
index 0000000000..baccd2244e
--- /dev/null
+++ b/spec/rubyspec/core/process/setpriority_spec.rb
@@ -0,0 +1,60 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+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)
+ end
+ end
+ end
+
+ # Darwin and FreeBSD don't seem to handle these at all, getting all out of
+ # 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
+ end
+
+ ok.should == true
+ end
+ end
+ end
+
+ platform_is_not :windows do
+ 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
+ end
+ end
+ end
+
+end