diff options
Diffstat (limited to 'test/zlib/test_zlib.rb')
-rw-r--r-- | test/zlib/test_zlib.rb | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/test/zlib/test_zlib.rb b/test/zlib/test_zlib.rb index 7d703d15e4..e2cb4e3755 100644 --- a/test/zlib/test_zlib.rb +++ b/test/zlib/test_zlib.rb @@ -3,6 +3,7 @@ require 'test/unit' require 'stringio' require 'tempfile' +require 'securerandom' begin require 'zlib' @@ -443,6 +444,70 @@ if defined? Zlib assert_raise(Zlib::StreamError) { z.set_dictionary("foo") } z.close end + + def test_multithread_deflate + zd = Zlib::Deflate.new + s = "x" * 10000 + (0...10).map do |x| + Thread.new do + 1000.times { zd.deflate(s) } + end + end.each do |th| + th.join + end + ensure + zd&.finish + zd&.close + end + + def test_multithread_inflate + zi = Zlib::Inflate.new + s = Zlib.deflate("x" * 10000) + (0...10).map do |x| + Thread.new do + 1000.times { zi.inflate(s) } + end + end.each do |th| + th.join + end + ensure + zi&.finish + zi&.close + end + + def test_recursive_deflate + original_gc_stress = GC.stress + GC.stress = true + zd = Zlib::Deflate.new + + s = SecureRandom.random_bytes(1024**2) + assert_raise(Zlib::InProgressError) do + zd.deflate(s) do + zd.deflate(s) + end + end + ensure + GC.stress = original_gc_stress + zd&.finish + zd&.close + end + + def test_recursive_inflate + original_gc_stress = GC.stress + GC.stress = true + zi = Zlib::Inflate.new + + s = Zlib.deflate(SecureRandom.random_bytes(1024**2)) + + assert_raise(Zlib::InProgressError) do + zi.inflate(s) do + zi.inflate(s) + end + end + ensure + GC.stress = original_gc_stress + zi&.close + end end class TestZlibGzipFile < Test::Unit::TestCase |