diff options
Diffstat (limited to 'test/mgmt.rb')
-rw-r--r-- | test/mgmt.rb | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/test/mgmt.rb b/test/mgmt.rb index 373cd69..1086f56 100644 --- a/test/mgmt.rb +++ b/test/mgmt.rb @@ -4,6 +4,7 @@ # License: GPLv3 or later (see COPYING for details) require 'test/test_helper' require 'digest/md5' +require 'timeout' class TestMgmt < Test::Unit::TestCase def setup @@ -238,28 +239,42 @@ class TestMgmt < Test::Unit::TestCase # ensure aborted requests do not trigger failure in graceful shutdown def test_concurrent_md5_fsck_abort sparse_file_prepare + nabort = 5 File.open("#@tmpdir/dev666/sparse-file.fid") do |fp| - if fp.respond_to?(:advise) - # clear the cache - fp.advise(:dontneed) - req = "MD5 /dev666/sparse-file.fid fsck\r\n" - starter = get_client - clients = (1..5).map { get_client } - - starter.write(req) - threads = clients.map do |c| - Thread.new(c) do |client| - client.write(req) - client.shutdown - client.close - :ok - end + unless fp.respond_to?(:advise) + skip("IO#advise not supported, skipping test") rescue nil + return + end + # clear the cache + fp.advise(:dontneed) + req = "MD5 /dev666/sparse-file.fid fsck\r\n" + starter = get_client + clients = (1..nabort).map { get_client } + + starter.write(req) + threads = clients.map do |c| + Thread.new(c) do |client| + client.write(req) + client.shutdown + client.close + :ok end - threads.each { |thr| assert_equal :ok, thr.value } - line = starter.gets - assert_match(%r{\A/dev666/sparse-file\.fid MD5=[a-f0-9]{32}\r\n}, line) - starter.close end + threads.each { |thr| assert_equal :ok, thr.value } + line = starter.gets + assert_match(%r{\A/dev666/sparse-file\.fid MD5=[a-f0-9]{32}\r\n}, line) + starter.close + + lines = nil + Timeout.timeout(30) do + begin + @err.rewind + lines = @err.readlines.grep(/aborted while waiting for fsck/) + end while lines.empty? && sleep(0.05) + end + assert lines[0], lines.inspect + @err.rewind + @err.truncate(0) end end |