redirecting some ugly output when running tests
This commit is contained in:
parent
3a613ef1b2
commit
692c8cf790
@ -202,6 +202,7 @@ class MasterTest < Test::Unit::TestCase
|
||||
|
||||
context "running a local worker" do
|
||||
setup do
|
||||
capture_stderr do # redirect stderr
|
||||
@pid = Process.fork do
|
||||
Hydra::Master.new(
|
||||
:files => [test_file] * 6,
|
||||
@ -212,6 +213,7 @@ class MasterTest < Test::Unit::TestCase
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should "run runner_end on successful termination" do
|
||||
Process.waitpid @pid
|
||||
@ -224,7 +226,9 @@ class MasterTest < Test::Unit::TestCase
|
||||
|
||||
should "run runner_end after interruption signal" do
|
||||
wait_for_runner_to_begin
|
||||
|
||||
Process.kill 'SIGINT', @pid
|
||||
|
||||
Process.waitpid @pid
|
||||
|
||||
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
|
||||
setup do
|
||||
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
|
||||
Hydra::Master.new(
|
||||
:files => [test_file] * 6,
|
||||
@ -251,6 +256,7 @@ class MasterTest < Test::Unit::TestCase
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
teardown do
|
||||
FileUtils.rm_f(@remote_init_file) unless @protect_init_file
|
||||
|
@ -80,6 +80,7 @@ class RunnerTest < Test::Unit::TestCase
|
||||
# because of all the crap cucumber pulls in
|
||||
# we run this in a fork to not contaminate
|
||||
# the main test environment
|
||||
capture_stderr do # redirect stderr
|
||||
pid = Process.fork do
|
||||
runner = Hydra::Runner.new(:io => File.new('/dev/null', 'w'))
|
||||
runner.run_file(cucumber_feature_file)
|
||||
@ -95,6 +96,7 @@ class RunnerTest < Test::Unit::TestCase
|
||||
end
|
||||
Process.wait pid
|
||||
end
|
||||
end
|
||||
|
||||
should "be able to run a runner over ssh" do
|
||||
send_file_to_ssh_runner_and_verify_completion
|
||||
|
@ -4,6 +4,7 @@ gem 'shoulda', '2.10.3'
|
||||
gem 'rspec', '2.0.0.beta.19'
|
||||
require 'shoulda'
|
||||
require 'tmpdir'
|
||||
require "stringio"
|
||||
|
||||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
||||
$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'))
|
||||
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
|
||||
#test can pass in slower machines. This helps to speed up the tests
|
||||
def wait_for_file_for_a_while file, time_to_wait
|
||||
|
Loading…
Reference in New Issue
Block a user