ruby-changes:72258
From: Jean <ko1@a...>
Date: Mon, 20 Jun 2022 20:05:59 +0900 (JST)
Subject: [ruby-changes:72258] c46824d094 (master): test_instrumentation_api.rb: Allow one less exit
https://git.ruby-lang.org/ruby.git/commit/?id=c46824d094 From c46824d0945c95172951a904f09c774b99a4deb3 Mon Sep 17 00:00:00 2001 From: Jean Boussier <jean.boussier@g...> Date: Mon, 20 Jun 2022 13:03:39 +0200 Subject: test_instrumentation_api.rb: Allow one less exit I suspect that sometimes on CI the last thread is prempted before eaching the exit hook causing the test to flake. I can't find a good way to force it to run. --- test/-ext-/thread/test_instrumentation_api.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/test/-ext-/thread/test_instrumentation_api.rb b/test/-ext-/thread/test_instrumentation_api.rb index 61e219101c..fe91c942c7 100644 --- a/test/-ext-/thread/test_instrumentation_api.rb +++ b/test/-ext-/thread/test_instrumentation_api.rb @@ -8,8 +8,6 @@ class TestThreadInstrumentation < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/thread/test_instrumentation_api.rb#L8 THREADS_COUNT = 3 - Give_more_time_to_the_native_threads_to_execute_their_EXIT_hook = EnvUtil.apply_timeout_scale(0.01) - def test_thread_instrumentation require '-test-/thread/instrumentation' Bug::ThreadInstrumentation.reset_counters @@ -20,11 +18,11 @@ class TestThreadInstrumentation < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/thread/test_instrumentation_api.rb#L18 assert_equal [false] * THREADS_COUNT, threads.map(&:status) counters = Bug::ThreadInstrumentation.counters counters.each do |c| - assert_predicate c,:nonzero?, "Call counters: #{counters.inspect}" + assert_predicate c, :nonzero?, "Call counters: #{counters.inspect}" end - sleep(Give_more_time_to_the_native_threads_to_execute_their_EXIT_hook) - assert_equal counters.first, counters.last # exited as many times as we entered + assert_equal THREADS_COUNT, counters.first + assert_in_delta THREADS_COUNT, counters.last, 1 # It's possible that a thread didn't execute its EXIT hook yet. ensure Bug::ThreadInstrumentation::unregister_callback end @@ -43,7 +41,6 @@ class TestThreadInstrumentation < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/thread/test_instrumentation_api.rb#L41 Bug::ThreadInstrumentation.reset_counters threads = threaded_cpu_work write_pipe.write(Marshal.dump(threads.map(&:status))) - sleep(Give_more_time_to_the_native_threads_to_execute_their_EXIT_hook) write_pipe.write(Marshal.dump(Bug::ThreadInstrumentation.counters)) write_pipe.close exit!(0) @@ -61,7 +58,8 @@ class TestThreadInstrumentation < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/thread/test_instrumentation_api.rb#L58 assert_predicate c, :nonzero?, "Call counters: #{counters.inspect}" end - assert_equal counters.first, counters.last # exited as many times as we entered + assert_equal THREADS_COUNT, counters.first + assert_in_delta THREADS_COUNT, counters.last, 1 # It's possible that a thread didn't execute its EXIT hook yet. ensure Bug::ThreadInstrumentation::unregister_callback end -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/