ruby-changes:54299
From: normal <ko1@a...>
Date: Sun, 23 Dec 2018 17:42:50 +0900 (JST)
Subject: [ruby-changes:54299] normal:r66508 (trunk): test/ruby/test_thread.rb (test_fork_while_parent_locked): rewrite to avoid OOM
normal 2018-12-23 17:42:44 +0900 (Sun, 23 Dec 2018) New Revision: 66508 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66508 Log: test/ruby/test_thread.rb (test_fork_while_parent_locked): rewrite to avoid OOM Instead of using a torture test, trigger the condition for the old segfault in [Bug #15383] exactly. [ruby-core:90676] [Bug #15430] Modified files: trunk/test/ruby/test_thread.rb Index: test/ruby/test_thread.rb =================================================================== --- test/ruby/test_thread.rb (revision 66507) +++ test/ruby/test_thread.rb (revision 66508) @@ -1241,44 +1241,23 @@ q.pop https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L1241 def test_fork_while_parent_locked skip 'needs fork' unless Process.respond_to?(:fork) - require 'tempfile' m = Thread::Mutex.new - failures = 0 - run = true - errs = '' - nr = 25 # reduce if more SIGKILL in tests - tmps = nr.times.map { Tempfile.new('Bug.15430.diagnosis') } - thrs = nr.times.map do |_i| - Thread.new(_i) do |i| - t = tmps[i] - t.sync = true - while run - pid = fork do - STDERR.reopen(t.path) - tmps.each(&:close) - m.synchronize {} - end - m.synchronize {} - _, st = Process.waitpid2(pid) - unless st.success? - m.synchronize do - failures += 1 - if errs.empty? - errs = st.inspect << t.read - t.rewind - end - end - end - end + nr = 1 + thrs = [] + m.synchronize do + thrs = nr.times.map { Thread.new { m.synchronize {} } } + thrs.each { Thread.pass } + pid = fork do + m.locked? or exit!(2) + thrs = nr.times.map { Thread.new { m.synchronize {} } } + m.unlock + thrs.each { |t| t.join(1) == t or exit!(1) } + exit!(0) end + _, st = Process.waitpid2(pid) + assert_predicate st, :success?, '[ruby-core:90312] [Bug #15383]' end - sleep 0.5 - run = false - thrs.each(&:join) - assert_empty errs, "lower `nr' if SIGKILL because of RLIMIT_NPROC limit" - assert_equal 0, failures, '[ruby-core:90312] [Bug #15383]' - ensure - tmps&.each(&:close!) + thrs.each { |t| assert_same t, t.join(1) } end def test_fork_while_mutex_locked_by_forker -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/