diff options
author | Charles Oliver Nutter <[email protected]> | 2023-05-19 09:11:43 -0500 |
---|---|---|
committer | Charles Oliver Nutter <[email protected]> | 2023-05-22 20:49:53 -0400 |
commit | f890345c03dc48072167df4bce45bc506dba2a1d () | |
tree | 6326c62d19480784d24996d49c3594f8626e4628 /test/ruby/test_thread_queue.rb | |
parent | ed7c7657ae0065a5007b443d146590e6e6a9dcbe (diff) |
Ensure producer threads do not start running early
This test caused issues occasionally on JRuby because it's possible for a producer thread to run to completion before the status checks begin. This results in Thread#status returning false and the =~ call triggering a warning (3.1) or error (3.2) and either emitting thousands of deprecation warnings or failing outright. The here introduces a mutex that remains locked until all producer threads are seen to have started. The lock is then released and the test proceeds. This prevents any producers from running to completion, which in turn prevents consumers running to completion, avoiding the warnings or error calling =~ on false. This also modifies the status checks to to_s the thread status, preventing any prematurely terminated threads from triggering similar deprecation warnings or missing method errors when =~ is called on nil.
Notes: Merged: https://.com/ruby/ruby/pull/7830
-rw-r--r-- | test/ruby/test_thread_queue.rb | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -585,9 +585,14 @@ class TestThreadQueue < Test::Unit::TestCase count_items = rand(3000..5000) count_producers = rand(10..20) producers = count_producers.times.map do Thread.new do - sleep(rand / 100) count_items.times{|i| q << [i,"#{i} for #{Thread.current.inspect}"]} end end @@ -605,9 +610,11 @@ class TestThreadQueue < Test::Unit::TestCase # No dead or finished threads, give up to 10 seconds to start running t = Time.now - Thread.pass until Time.now - t > 10 || (consumers + producers).all?{|thr| thr.status =~ /\A(?:run|sleep)\z/} - assert (consumers + producers).all?{|thr| thr.status =~ /\A(?:run|sleep)\z/}, 'no threads running' # just exercising the concurrency of the support methods. counter = Thread.new do |