|
1 | 1 | require_relative '../../spec_helper' |
| 2 | +require_relative 'fixtures/common' |
2 | 3 |
|
3 | 4 | describe "Process.detach" do |
4 | | - platform_is_not :windows do |
5 | | - it "returns a thread" do |
6 | | - pid = Process.fork { Process.exit! } |
7 | | - thr = Process.detach(pid) |
8 | | - thr.should.is_a?(Thread) |
9 | | - thr.join |
10 | | - end |
| 5 | + ProcessSpecs.use_system_ruby(self) |
11 | 6 |
|
12 | | - it "produces the exit Process::Status as the thread value" do |
13 | | - pid = Process.fork { Process.exit! } |
14 | | - thr = Process.detach(pid) |
15 | | - thr.join |
| 7 | + it "returns a thread" do |
| 8 | + pid = Process.spawn(*ruby_exe, "-e", "exit") |
| 9 | + thr = Process.detach(pid) |
| 10 | + thr.should.is_a?(Thread) |
| 11 | + thr.join |
| 12 | + end |
16 | 13 |
|
17 | | - status = thr.value |
18 | | - status.should.is_a?(Process::Status) |
19 | | - status.pid.should == pid |
20 | | - end |
| 14 | + it "produces the exit Process::Status as the thread value" do |
| 15 | + pid = Process.spawn(*ruby_exe, "-e", "exit") |
| 16 | + thr = Process.detach(pid) |
| 17 | + thr.join |
| 18 | + |
| 19 | + status = thr.value |
| 20 | + status.should.is_a?(Process::Status) |
| 21 | + status.pid.should == pid |
| 22 | + end |
21 | 23 |
|
22 | | - platform_is_not :openbsd do |
23 | | - it "reaps the child process's status automatically" do |
24 | | - pid = Process.fork { Process.exit! } |
25 | | - Process.detach(pid).join |
26 | | - -> { Process.waitpid(pid) }.should.raise(Errno::ECHILD) |
27 | | - end |
| 24 | + platform_is_not :openbsd do |
| 25 | + it "reaps the child process's status automatically" do |
| 26 | + pid = Process.spawn(*ruby_exe, "-e", "exit") |
| 27 | + Process.detach(pid).join |
| 28 | + -> { Process.waitpid(pid) }.should.raise(Errno::ECHILD) |
28 | 29 | end |
| 30 | + end |
29 | 31 |
|
30 | | - it "sets the :pid thread-local to the PID" do |
31 | | - pid = Process.fork { Process.exit! } |
32 | | - thr = Process.detach(pid) |
33 | | - thr.join |
| 32 | + it "sets the :pid thread-local to the PID" do |
| 33 | + pid = Process.spawn(*ruby_exe, "-e", "exit") |
| 34 | + thr = Process.detach(pid) |
| 35 | + thr.join |
34 | 36 |
|
35 | | - thr[:pid].should == pid |
36 | | - end |
| 37 | + thr[:pid].should == pid |
| 38 | + end |
37 | 39 |
|
38 | | - it "provides a #pid method on the returned thread which returns the PID" do |
39 | | - pid = Process.fork { Process.exit! } |
40 | | - thr = Process.detach(pid) |
41 | | - thr.join |
| 40 | + it "provides a #pid method on the returned thread which returns the PID" do |
| 41 | + pid = Process.spawn(*ruby_exe, "-e", "exit") |
| 42 | + thr = Process.detach(pid) |
| 43 | + thr.join |
42 | 44 |
|
43 | | - thr.pid.should == pid |
44 | | - end |
| 45 | + thr.pid.should == pid |
| 46 | + end |
45 | 47 |
|
46 | | - it "tolerates not existing child process pid" do |
47 | | - # Use a value that is close to the INT_MAX (pid usually is signed int). |
48 | | - # It should (at least) be greater than allowed pid limit value that depends on OS. |
49 | | - pid_not_existing = 2.pow(30) |
| 48 | + it "tolerates not existing child process pid" do |
| 49 | + # Use a value that is close to the INT_MAX (pid usually is signed int). |
| 50 | + # It should (at least) be greater than allowed pid limit value that depends on OS. |
| 51 | + pid_not_existing = 2.pow(30) |
50 | 52 |
|
51 | | - # Check that there is no a child process with this hardcoded pid. |
52 | | - # Command `kill 0 pid`: |
53 | | - # - returns "1" if a process exists and |
54 | | - # - raises Errno::ESRCH otherwise |
55 | | - -> { Process.kill(0, pid_not_existing) }.should.raise(Errno::ESRCH) |
| 53 | + # Check that there is no a child process with this hardcoded pid. |
| 54 | + # Command `kill 0 pid`: |
| 55 | + # - returns "1" if a process exists and |
| 56 | + # - raises Errno::ESRCH otherwise |
| 57 | + -> { Process.kill(0, pid_not_existing) }.should.raise(Errno::ESRCH) |
56 | 58 |
|
57 | | - thr = Process.detach(pid_not_existing) |
58 | | - thr.join |
| 59 | + thr = Process.detach(pid_not_existing) |
| 60 | + thr.join |
59 | 61 |
|
60 | | - thr.should.is_a?(Thread) |
61 | | - end |
| 62 | + thr.should.is_a?(Thread) |
| 63 | + end |
62 | 64 |
|
63 | | - it "calls #to_int to implicitly convert non-Integer pid to Integer" do |
64 | | - pid = MockObject.new('mock-enumerable') |
65 | | - pid.should_receive(:to_int).and_return(100500) |
| 65 | + it "calls #to_int to implicitly convert non-Integer pid to Integer" do |
| 66 | + pid = MockObject.new('mock-enumerable') |
| 67 | + pid.should_receive(:to_int).and_return(100500) |
66 | 68 |
|
67 | | - Process.detach(pid).join |
68 | | - end |
| 69 | + Process.detach(pid).join |
| 70 | + end |
69 | 71 |
|
70 | | - it "raises TypeError when pid argument does not have #to_int method" do |
71 | | - -> { Process.detach(Object.new) }.should.raise(TypeError, "no implicit conversion of Object into Integer") |
72 | | - end |
| 72 | + it "raises TypeError when pid argument does not have #to_int method" do |
| 73 | + -> { Process.detach(Object.new) }.should.raise(TypeError, "no implicit conversion of Object into Integer") |
| 74 | + end |
73 | 75 |
|
74 | | - it "raises TypeError when #to_int returns non-Integer value" do |
75 | | - pid = MockObject.new('mock-enumerable') |
76 | | - pid.should_receive(:to_int).and_return(:symbol) |
| 76 | + it "raises TypeError when #to_int returns non-Integer value" do |
| 77 | + pid = MockObject.new('mock-enumerable') |
| 78 | + pid.should_receive(:to_int).and_return(:symbol) |
77 | 79 |
|
78 | | - -> { Process.detach(pid) }.should raise_consistent_error(TypeError, "can't convert MockObject into Integer (MockObject#to_int gives Symbol)") |
79 | | - end |
| 80 | + -> { Process.detach(pid) }.should raise_consistent_error(TypeError, "can't convert MockObject into Integer (MockObject#to_int gives Symbol)") |
80 | 81 | end |
81 | 82 | end |
0 commit comments