为什么在 Minitest 测试中 fork 以非零退出?
Why fork exits with non-zero in Minitest test?
这是代码:
require 'minitest/autorun'
class Foo < Minitest::Test
def test_foo
Process.fork do
exit(0)
end
p Process.waitall
end
end
这是输出:
$ ruby a.rb
Run options: --seed 40445
# Running:
[[41827, #<Process::Status: pid 41827 exit 1>]]
.
Finished in 0.016218s, 61.6599 runs/s, 0.0000 assertions/s.
1 runs, 0 assertions, 0 failures, 0 errors, 0 skips
为什么退出代码不为零?
没有 Minitest 的相同代码工作得很好:
Process.fork do
exit(0)
end
p Process.waitall
怎么了?
https://github.com/seattlerb/minitest/issues/467
The problem is that fork
duplicates the at_exit
handlers of the parent process. Minitest uses at_exit
to run the tests so you're hitting up against that. From the fork doco: "The child process can exit using Kernel.exit!
to avoid running any at_exit
functions."
这是代码:
require 'minitest/autorun'
class Foo < Minitest::Test
def test_foo
Process.fork do
exit(0)
end
p Process.waitall
end
end
这是输出:
$ ruby a.rb
Run options: --seed 40445
# Running:
[[41827, #<Process::Status: pid 41827 exit 1>]]
.
Finished in 0.016218s, 61.6599 runs/s, 0.0000 assertions/s.
1 runs, 0 assertions, 0 failures, 0 errors, 0 skips
为什么退出代码不为零?
没有 Minitest 的相同代码工作得很好:
Process.fork do
exit(0)
end
p Process.waitall
怎么了?
https://github.com/seattlerb/minitest/issues/467
The problem is that
fork
duplicates theat_exit
handlers of the parent process. Minitest usesat_exit
to run the tests so you're hitting up against that. From the fork doco: "The child process can exit usingKernel.exit!
to avoid running anyat_exit
functions."