Skip to content

Commit

Permalink
Merge pull request #1250 from fluent/fix-test-out-secondary-file
Browse files Browse the repository at this point in the history
test_out_secondary_file: wait for disk I/O completion in tests
  • Loading branch information
tagomoris authored Sep 28, 2016
2 parents 463ac14 + 896f49b commit 80d0ce2
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions test/plugin/test_out_secondary_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,19 @@ def check_gzipped_result(path, expect)
# Zlib::GzipReader has a bug of concatenated file: https://bugs.ruby-lang.org/issues/9790
# Following code from https://www.ruby-forum.com/topic/971591#979520
result = ""
File.open(path, "rb") { |io|
loop do
gzr = Zlib::GzipReader.new(io)
result << gzr.read
unused = gzr.unused
gzr.finish
break if unused.nil?
io.pos -= unused.length
end
}
waiting(10) do
# we can expect that GzipReader#read can wait unflushed raw data of `io` on disk
File.open(path, "rb") { |io|
loop do
gzr = Zlib::GzipReader.new(io)
result << gzr.read
unused = gzr.unused
gzr.finish
break if unused.nil?
io.pos -= unused.length
end
}
end

assert_equal expect, result
end
Expand Down Expand Up @@ -155,10 +158,15 @@ def create_chunk(primary, metadata, es)
basename out_file_test
], @primary)

path = d.instance.write(@chunk)
msgpack_binary = @es.to_msgpack_stream.force_encoding('ASCII-8BIT')

path = d.instance.write(@chunk)
assert_equal "#{TMP_DIR}/out_file_test.0", path
assert_equal File.read(path), @es.to_msgpack_stream.force_encoding('ASCII-8BIT')
waiting(5) do
sleep 0.1 until File.stat(path).size == msgpack_binary.size
end

assert_equal File.read(path), msgpack_binary
end

test 'path should be incremental when append option is false' do
Expand Down

0 comments on commit 80d0ce2

Please sign in to comment.