Skip to content

Commit 29871ee

Browse files
committed
Fix a spec for Process.detach and use greater hardcoded pid of not existing process
1 parent 278dbd3 commit 29871ee

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

spec/ruby/core/process/detach_spec.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,17 @@
4444
end
4545

4646
it "tolerates not existing child process pid" do
47-
# ensure there is no child process with this hardcoded pid
48-
# `kill 0 pid` for existing process returns "1" and raises Errno::ESRCH if process doesn't exist
49-
-> { Process.kill(0, 100500) }.should raise_error(Errno::ESRCH)
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)
5050

51-
thr = Process.detach(100500)
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_error(Errno::ESRCH)
56+
57+
thr = Process.detach(pid_not_existing)
5258
thr.join
5359

5460
thr.should be_kind_of(Thread)

0 commit comments

Comments
 (0)