mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64187 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
80e973f0e6
commit
ff1e665729
1 changed files with 21 additions and 6 deletions
|
@ -3804,18 +3804,33 @@ __END__
|
||||||
|
|
||||||
def test_select_leak
|
def test_select_leak
|
||||||
skip 'MJIT uses too much memory' if RubyVM::MJIT.enabled?
|
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
|
r, w = IO.pipe
|
||||||
rset = [r]
|
rset = [r]
|
||||||
wset = [w]
|
wset = [w]
|
||||||
|
exc = StandardError.new(-"select used to leak on exception")
|
||||||
|
exc.set_backtrace([])
|
||||||
Thread.new { IO.select(rset, wset, nil, 0) }.join
|
Thread.new { IO.select(rset, wset, nil, 0) }.join
|
||||||
end;
|
end;
|
||||||
20_000.times do
|
th = Thread.new do
|
||||||
th = Thread.new { IO.select(rset, wset) }
|
begin
|
||||||
Thread.pass until th.stop?
|
IO.select(rset, wset)
|
||||||
th.kill
|
rescue => e
|
||||||
th.join
|
retry
|
||||||
|
end while true
|
||||||
end
|
end
|
||||||
|
50_000.times do
|
||||||
|
Thread.pass until th.stop?
|
||||||
|
th.raise(exc)
|
||||||
|
end
|
||||||
|
th.kill
|
||||||
|
th.join
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue