diff options
Diffstat (limited to 'test/mgmt-iostat.rb')
-rw-r--r-- | test/mgmt-iostat.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/mgmt-iostat.rb b/test/mgmt-iostat.rb index 905430c..6171ded 100644 --- a/test/mgmt-iostat.rb +++ b/test/mgmt-iostat.rb @@ -3,6 +3,7 @@ # Copyright (C) 2012-2013, Eric Wong <normalperson@yhbt.net> # License: GPLv3 or later (see COPYING for details) require 'test/test_helper' +require 'timeout' class TestMgmtIostat < Test::Unit::TestCase TEST_PATH = File.dirname(__FILE__) + ":#{ENV['PATH']}" @@ -37,6 +38,44 @@ class TestMgmtIostat < Test::Unit::TestCase FileUtils.rm_rf(@tmpdir) end + def __test_iostat_dies(workers = false) + Dir.mkdir "#@tmpdir/dev666" + err = Tempfile.new('err') + @pid = fork do + ENV["PATH"] = TEST_PATH + ENV["MOG_IOSTAT_CMD"] = "#{iostat_mock} #{@iostat_pid.path} slow" + $stderr.reopen(err.path, 'a') + @cmd << workers if workers + exec(*@cmd) + end + iostat_pid = nil + Timeout.timeout(30) do + begin + iostat_pid = @iostat_pid.read.to_i + end while iostat_pid == 0 && sleep(0.05) + Process.kill(:TERM, iostat_pid) + end + + expect = %r{iostat done \(pid=#{iostat_pid}, status=\d} + Timeout.timeout(30) do + loop do + stderr = File.read(err.path) + break if stderr =~ expect + sleep 0.05 + end + end + ensure + err.close! + end + + def test_iostat_dies + __test_iostat_dies + end + + def test_iostat_dies_with_workers + __test_iostat_dies("--worker-processes=1") + end + def test_iostat_fast Dir.mkdir "#@tmpdir/dev666" @pid = fork do |