diff options
-rw-r--r-- | cmogstored.c | 2 | ||||
-rw-r--r-- | test/mgmt-iostat.rb | 39 |
2 files changed, 39 insertions, 2 deletions
diff --git a/cmogstored.c b/cmogstored.c index 31d8e64..64b932d 100644 --- a/cmogstored.c +++ b/cmogstored.c @@ -461,8 +461,6 @@ static void process_died(pid_t pid, int status) switch (id) { case MOG_PROC_IOSTAT: - assert(mog_main.worker_processes == 0 && - "master process registered iostat process"); iostat_died(pid, status); return; case MOG_PROC_UPGRADE: 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 |