Use IO.popen
to fork and exit the child process without cleanup
This commit is contained in:
parent
8b98b9e274
commit
a6e2f3fd8d
Notes:
git
2022-07-12 19:43:35 +09:00
@ -41,25 +41,21 @@ class TestThreadInstrumentation < Test::Unit::TestCase
|
|||||||
def test_thread_instrumentation_fork_safe
|
def test_thread_instrumentation_fork_safe
|
||||||
skip "No fork()" unless Process.respond_to?(:fork)
|
skip "No fork()" unless Process.respond_to?(:fork)
|
||||||
|
|
||||||
read_pipe, write_pipe = IO.pipe
|
thread_statuses = counters = nil
|
||||||
|
IO.popen("-") do |read_pipe|
|
||||||
pid = fork do
|
if read_pipe
|
||||||
|
thread_statuses = Marshal.load(read_pipe)
|
||||||
|
counters = Marshal.load(read_pipe)
|
||||||
|
else
|
||||||
Bug::ThreadInstrumentation.reset_counters
|
Bug::ThreadInstrumentation.reset_counters
|
||||||
threads = threaded_cpu_work
|
threads = threaded_cpu_work
|
||||||
write_pipe.write(Marshal.dump(threads.map(&:status)))
|
Marshal.dump(threads.map(&:status), STDOUT)
|
||||||
write_pipe.write(Marshal.dump(Bug::ThreadInstrumentation.counters))
|
Marshal.dump(Bug::ThreadInstrumentation.counters, STDOUT)
|
||||||
write_pipe.close
|
|
||||||
exit!(0)
|
|
||||||
end
|
end
|
||||||
write_pipe.close
|
end
|
||||||
_, status = Process.wait2(pid)
|
assert_predicate $?, :success?
|
||||||
assert_predicate status, :success?
|
|
||||||
|
|
||||||
thread_statuses = Marshal.load(read_pipe)
|
|
||||||
assert_equal [false] * THREADS_COUNT, thread_statuses
|
assert_equal [false] * THREADS_COUNT, thread_statuses
|
||||||
|
|
||||||
counters = Marshal.load(read_pipe)
|
|
||||||
read_pipe.close
|
|
||||||
counters.each do |c|
|
counters.each do |c|
|
||||||
assert_predicate c, :nonzero?, "Call counters: #{counters.inspect}"
|
assert_predicate c, :nonzero?, "Call counters: #{counters.inspect}"
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user