ruby-changes:51972
From: normal <ko1@a...>
Date: Sun, 5 Aug 2018 08:33:41 +0900 (JST)
Subject: [ruby-changes:51972] normal:r64187 (trunk): test/ruby/test_io.rb (test_select_leak): speedup and reduce memory use
normal 2018-08-05 08:33:38 +0900 (Sun, 05 Aug 2018) New Revision: 64187 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64187 Log: test/ruby/test_io.rb (test_select_leak): speedup and reduce memory use We can reuse the sub-thread and exception with Thread#raise to reproduce the old memory leak with less overhead. This allows us to to run more iterations and improve reliability of the actual test, particularly on platforms without USE_THREAD_CACHE. For glibc and jemalloc, also limit arena count to avoid inadvertant growth. Modified files: trunk/test/ruby/test_io.rb Index: test/ruby/test_io.rb =================================================================== --- test/ruby/test_io.rb (revision 64186) +++ test/ruby/test_io.rb (revision 64187) @@ -3804,18 +3804,33 @@ __END__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L3804 def test_select_leak skip 'MJIT uses too much memory' if RubyVM::MJIT.enabled? - assert_no_memory_leak([], <<-"end;", <<-"end;", rss: true, timeout: 60) + # avoid malloc arena explosion from glibc and jemalloc: + env = { + 'MALLOC_ARENA_MAX' => '1', + 'MALLOC_ARENA_TEST' => '1', + 'MALLOC_CONF' => 'narenas:1', + } + assert_no_memory_leak([env], <<-"end;", <<-"end;", rss: true, timeout: 60) r, w = IO.pipe rset = [r] wset = [w] + exc = StandardError.new(-"select used to leak on exception") + exc.set_backtrace([]) Thread.new { IO.select(rset, wset, nil, 0) }.join end; - 20_000.times do - th = Thread.new { IO.select(rset, wset) } + th = Thread.new do + begin + IO.select(rset, wset) + rescue => e + retry + end while true + end + 50_000.times do Thread.pass until th.stop? - th.kill - th.join + th.raise(exc) end + th.kill + th.join end; end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/