2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../../spec_helper'
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
describe "Process.wait2" do
|
|
|
|
before :all do
|
|
|
|
# HACK: this kludge is temporarily necessary because some
|
|
|
|
# misbehaving spec somewhere else does not clear processes
|
2018-07-04 23:02:33 -04:00
|
|
|
# Note: background processes are unavoidable with MJIT,
|
|
|
|
# but we shouldn't reap them from Ruby-space
|
2017-05-07 08:04:49 -04:00
|
|
|
begin
|
2017-10-28 11:15:48 -04:00
|
|
|
Process.wait(-1, Process::WNOHANG)
|
2018-07-04 23:02:33 -04:00
|
|
|
without_feature :mjit do
|
|
|
|
$stderr.puts "Leaked process before wait2 specs! Waiting for it"
|
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
leaked = Process.waitall
|
2018-07-04 23:02:33 -04:00
|
|
|
$stderr.puts "leaked before wait2 specs: #{leaked}" unless leaked.empty?
|
2019-04-27 12:53:23 -04:00
|
|
|
# Ruby-space should not see PIDs used by mjit
|
|
|
|
leaked.should be_empty
|
2017-10-28 11:15:48 -04:00
|
|
|
rescue Errno::ECHILD # No child processes
|
2017-05-07 08:04:49 -04:00
|
|
|
rescue NotImplementedError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-04 23:02:33 -04:00
|
|
|
platform_is_not :windows do
|
|
|
|
it "returns the pid and status of child process" do
|
|
|
|
pidf = Process.fork { Process.exit! 99 }
|
|
|
|
results = Process.wait2
|
|
|
|
results.size.should == 2
|
|
|
|
pidw, status = results
|
|
|
|
pidf.should == pidw
|
|
|
|
status.exitstatus.should == 99
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
2018-07-04 23:02:33 -04:00
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2018-07-04 23:02:33 -04:00
|
|
|
it "raises a StandardError if no child processes exist" do
|
|
|
|
lambda { Process.wait2 }.should raise_error(Errno::ECHILD)
|
|
|
|
lambda { Process.wait2 }.should raise_error(StandardError)
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
end
|