Permalink
Browse files

Spec Process.detach thread behavior

  • Loading branch information...
1 parent a6fb7b6 commit ba0c103bd25cc10d4fd26769d92c1f6009a2c130 @jfirebaugh jfirebaugh committed May 7, 2012
Showing with 24 additions and 5 deletions.
  1. +24 −5 spec/ruby/core/process/detach_spec.rb
@@ -4,16 +4,35 @@
describe "Process.detach" do
platform_is_not :windows do
it "returns a thread" do
- p1 = Process.fork { Process.exit! }
- Process.detach(p1).should be_kind_of(Thread)
+ pid = Process.fork { Process.exit! }
+ Process.detach(pid).should be_kind_of(Thread)
+ end
+
+ it "produces the exit Process::Status as the thread value" do
+ pid = Process.fork { Process.exit! }
+ status = Process.detach(pid).value
+ status.should be_kind_of(Process::Status)
+ status.pid.should == pid
end
platform_is_not :openbsd do
it "reaps the child process's status automatically" do
- p1 = Process.fork { Process.exit! }
- th = Process.detach(p1)
+ pid = Process.fork { Process.exit! }
+ th = Process.detach(pid)
timeout(3) { th.join }
- lambda { Process.waitpid(p1) }.should raise_error(Errno::ECHILD)
+ lambda { Process.waitpid(pid) }.should raise_error(Errno::ECHILD)
+ end
+ end
+
+ ruby_version_is "1.9" do
+ it "sets the :pid thread-local to the PID" do
+ pid = Process.fork { Process.exit! }
+ Process.detach(pid)[:pid].should == pid
+ end
+
+ it "provides a #pid method on the returned thread which returns the PID" do
+ pid = Process.fork { Process.exit! }
+ Process.detach(pid).pid.should == pid
end
end
end

0 comments on commit ba0c103

Please sign in to comment.