redirecting some ugly output when running tests

This commit is contained in:
Arturo Pie 2011-06-01 17:29:45 -04:00
parent 3a613ef1b2
commit 692c8cf790
3 changed files with 55 additions and 34 deletions

View File

@ -202,6 +202,7 @@ class MasterTest < Test::Unit::TestCase
context "running a local worker" do context "running a local worker" do
setup do setup do
capture_stderr do # redirect stderr
@pid = Process.fork do @pid = Process.fork do
Hydra::Master.new( Hydra::Master.new(
:files => [test_file] * 6, :files => [test_file] * 6,
@ -212,6 +213,7 @@ class MasterTest < Test::Unit::TestCase
) )
end end
end end
end
should "run runner_end on successful termination" do should "run runner_end on successful termination" do
Process.waitpid @pid Process.waitpid @pid
@ -224,7 +226,9 @@ class MasterTest < Test::Unit::TestCase
should "run runner_end after interruption signal" do should "run runner_end after interruption signal" do
wait_for_runner_to_begin wait_for_runner_to_begin
Process.kill 'SIGINT', @pid Process.kill 'SIGINT', @pid
Process.waitpid @pid Process.waitpid @pid
wait_for_file_for_a_while alternate_target_file, 2 wait_for_file_for_a_while alternate_target_file, 2
@ -235,6 +239,7 @@ class MasterTest < Test::Unit::TestCase
context "running a remote worker" do context "running a remote worker" do
setup do setup do
copy_worker_init_file # this method has a protection to avoid erasing an existing worker_init_file copy_worker_init_file # this method has a protection to avoid erasing an existing worker_init_file
capture_stderr do # redirect stderr
@pid = Process.fork do @pid = Process.fork do
Hydra::Master.new( Hydra::Master.new(
:files => [test_file] * 6, :files => [test_file] * 6,
@ -251,6 +256,7 @@ class MasterTest < Test::Unit::TestCase
) )
end end
end end
end
teardown do teardown do
FileUtils.rm_f(@remote_init_file) unless @protect_init_file FileUtils.rm_f(@remote_init_file) unless @protect_init_file

View File

@ -80,6 +80,7 @@ class RunnerTest < Test::Unit::TestCase
# because of all the crap cucumber pulls in # because of all the crap cucumber pulls in
# we run this in a fork to not contaminate # we run this in a fork to not contaminate
# the main test environment # the main test environment
capture_stderr do # redirect stderr
pid = Process.fork do pid = Process.fork do
runner = Hydra::Runner.new(:io => File.new('/dev/null', 'w')) runner = Hydra::Runner.new(:io => File.new('/dev/null', 'w'))
runner.run_file(cucumber_feature_file) runner.run_file(cucumber_feature_file)
@ -95,6 +96,7 @@ class RunnerTest < Test::Unit::TestCase
end end
Process.wait pid Process.wait pid
end end
end
should "be able to run a runner over ssh" do should "be able to run a runner over ssh" do
send_file_to_ssh_runner_and_verify_completion send_file_to_ssh_runner_and_verify_completion

View File

@ -4,6 +4,7 @@ gem 'shoulda', '2.10.3'
gem 'rspec', '2.0.0.beta.19' gem 'rspec', '2.0.0.beta.19'
require 'shoulda' require 'shoulda'
require 'tmpdir' require 'tmpdir'
require "stringio"
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__)) $LOAD_PATH.unshift(File.dirname(__FILE__))
@ -65,6 +66,18 @@ class Test::Unit::TestCase
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'hydra_worker_init.rb')) File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'hydra_worker_init.rb'))
end end
def capture_stderr
# The output stream must be an IO-like object. In this case we capture it in
# an in-memory IO object so we can return the string value. You can assign any
# IO object here.
previous_stderr, $stderr = $stderr, StringIO.new
yield
$stderr.string
ensure
# Restore the previous value of stderr (typically equal to STDERR).
$stderr = previous_stderr
end
#this method allow us to wait for a file for a maximum number of time, so the #this method allow us to wait for a file for a maximum number of time, so the
#test can pass in slower machines. This helps to speed up the tests #test can pass in slower machines. This helps to speed up the tests
def wait_for_file_for_a_while file, time_to_wait def wait_for_file_for_a_while file, time_to_wait