diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-12-23 08:42:44 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-12-23 08:42:44 +0000 |
commit | 37bba27b2cc02febca403ae4a80042413b16fb15 (patch) | |
tree | 6b23bfa0e5a3ed04a7dd618bce1a45a9bbefc7ad /test/ruby | |
parent | e5d634260e7927db284fd7d2d656899443f5c53e (diff) | |
download | ruby-37bba27b2cc02febca403ae4a80042413b16fb15.tar.gz |
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]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_thread.rb | 49 |
1 files changed, 14 insertions, 35 deletions
diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb index 904e3e7fae..51c0338595 100644 --- a/test/ruby/test_thread.rb +++ b/test/ruby/test_thread.rb @@ -1241,44 +1241,23 @@ q.pop 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 |