aboutsummaryrefslogtreecommitdiffstats
path: root/test/-ext-
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-07-10 13:01:04 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-07-12 19:43:11 +0900
commita6e2f3fd8d98e511e4e2011bc1a45ba1bd9144a1 (patch)
treefe9e2c79e4e8c40fc48583107d5081ddc8c7021f /test/-ext-
parent8b98b9e274ea0a749044e044ee03ee1095aa75d0 (diff)
downloadruby-a6e2f3fd8d98e511e4e2011bc1a45ba1bd9144a1.tar.gz
Use `IO.popen` to fork and exit the child process without cleanup
Diffstat (limited to 'test/-ext-')
-rw-r--r--test/-ext-/thread/test_instrumentation_api.rb28
1 files changed, 12 insertions, 16 deletions
diff --git a/test/-ext-/thread/test_instrumentation_api.rb b/test/-ext-/thread/test_instrumentation_api.rb
index 4830789546..4e74a4cc6a 100644
--- a/test/-ext-/thread/test_instrumentation_api.rb
+++ b/test/-ext-/thread/test_instrumentation_api.rb
@@ -41,25 +41,21 @@ class TestThreadInstrumentation < Test::Unit::TestCase
def test_thread_instrumentation_fork_safe
skip "No fork()" unless Process.respond_to?(:fork)
- read_pipe, write_pipe = IO.pipe
-
- pid = fork do
- Bug::ThreadInstrumentation.reset_counters
- threads = threaded_cpu_work
- write_pipe.write(Marshal.dump(threads.map(&:status)))
- write_pipe.write(Marshal.dump(Bug::ThreadInstrumentation.counters))
- write_pipe.close
- exit!(0)
+ thread_statuses = counters = nil
+ IO.popen("-") do |read_pipe|
+ if read_pipe
+ thread_statuses = Marshal.load(read_pipe)
+ counters = Marshal.load(read_pipe)
+ else
+ Bug::ThreadInstrumentation.reset_counters
+ threads = threaded_cpu_work
+ Marshal.dump(threads.map(&:status), STDOUT)
+ Marshal.dump(Bug::ThreadInstrumentation.counters, STDOUT)
+ end
end
- write_pipe.close
- _, status = Process.wait2(pid)
- assert_predicate status, :success?
+ assert_predicate $?, :success?
- thread_statuses = Marshal.load(read_pipe)
assert_equal [false] * THREADS_COUNT, thread_statuses
-
- counters = Marshal.load(read_pipe)
- read_pipe.close
counters.each do |c|
assert_predicate c, :nonzero?, "Call counters: #{counters.inspect}"
end