From 5923fcad1a8e7d635dd66e00d965dffa4e6b8615 Mon Sep 17 00:00:00 2001 From: Yuta Iwama Date: Wed, 18 Mar 2020 18:42:43 +0900 Subject: [PATCH 1/2] Remove useless wait Signed-off-by: Yuta Iwama --- test/plugin/test_compressable.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/plugin/test_compressable.rb b/test/plugin/test_compressable.rb index c7d685cafb..0efa6f2eca 100644 --- a/test/plugin/test_compressable.rb +++ b/test/plugin/test_compressable.rb @@ -36,7 +36,6 @@ class CompressableTest < Test::Unit::TestCase test 'write decompressed data to IO with output_io option' do io = StringIO.new decompress(@gzipped_src, output_io: io) - waiting(10){ sleep 0.1 until @src == io.string } assert_equal @src, io.string end @@ -58,7 +57,6 @@ class CompressableTest < Test::Unit::TestCase output_io = StringIO.new decompress(input_io: input_io, output_io: output_io) - waiting(10){ sleep 0.1 until @src == output_io.string } assert_equal @src, output_io.string end From 5a24a7ae3c0e6cf3a881f6d068eb0a163fdab18c Mon Sep 17 00:00:00 2001 From: Yuta Iwama Date: Wed, 18 Mar 2020 18:43:33 +0900 Subject: [PATCH 2/2] it cannot compare gziped string Making gzip's header uses time so it doesn't return the same value. https://github.com/ruby/ruby/blob/afd23ed0491b9df0b6a1753a2f66cd3f80428930/ext/zlib/zlib.c#L2520 ```rb require 'zlib' require 'stringio' def compress(data, **kwargs) output_io = kwargs[:output_io] io = output_io || StringIO.new Zlib::GzipWriter.wrap(io, Zlib::DEFAULT_COMPRESSION, Zlib::FILTERED) do |gz| gz.write data end output_io || io.string end @src = 'text data for compressing' * 5 v = compress(@src) sleep 2 # needed io = StringIO.new a = compress(@src, output_io: io) v1 = a.string if v != v1 p v p v1 end ``` Signed-off-by: Yuta Iwama --- test/plugin/test_compressable.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/plugin/test_compressable.rb b/test/plugin/test_compressable.rb index 0efa6f2eca..96dfa318df 100644 --- a/test/plugin/test_compressable.rb +++ b/test/plugin/test_compressable.rb @@ -4,6 +4,12 @@ class CompressableTest < Test::Unit::TestCase include Fluent::Plugin::Compressable + def compress_assert_equal(expected, actual) + e = Zlib::GzipReader.new(StringIO.new(expected)).read + a = Zlib::GzipReader.new(StringIO.new(actual)).read + assert_equal(e, a) + end + sub_test_case '#compress' do setup do @src = 'text data for compressing' * 5 @@ -18,8 +24,7 @@ class CompressableTest < Test::Unit::TestCase test 'write compressed data to IO with output_io option' do io = StringIO.new compress(@src, output_io: io) - waiting(10){ sleep 0.1 until @gzipped_src == io.string } - assert_equal @gzipped_src, io.string + compress_assert_equal @gzipped_src, io.string end end