File: setpriority_spec.rb

package info (click to toggle)
jruby 1.7.26-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 84,572 kB
  • sloc: ruby: 669,910; java: 253,056; xml: 35,152; ansic: 9,187; yacc: 7,267; cpp: 5,244; sh: 1,036; makefile: 345; jsp: 48; tcl: 40
file content (60 lines) | stat: -rw-r--r-- 2,074 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require File.expand_path('../../../spec_helper', __FILE__)

describe "Process.setpriority" do
  # Needs a valid version written for Linux
  platform_is :os => :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 :os => [: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 :os => :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