redirecting some ugly output when running tests
This commit is contained in:
parent
3a613ef1b2
commit
692c8cf790
@ -202,14 +202,16 @@ class MasterTest < Test::Unit::TestCase
|
||||
|
||||
context "running a local worker" do
|
||||
setup do
|
||||
@pid = Process.fork do
|
||||
Hydra::Master.new(
|
||||
:files => [test_file] * 6,
|
||||
:autosort => false,
|
||||
:listeners => [@master_listener],
|
||||
:runner_listeners => [@runner_listener],
|
||||
:verbose => false
|
||||
)
|
||||
capture_stderr do # redirect stderr
|
||||
@pid = Process.fork do
|
||||
Hydra::Master.new(
|
||||
:files => [test_file] * 6,
|
||||
:autosort => false,
|
||||
:listeners => [@master_listener],
|
||||
:runner_listeners => [@runner_listener],
|
||||
:verbose => false
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -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,20 +239,22 @@ 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
|
||||
@pid = Process.fork do
|
||||
Hydra::Master.new(
|
||||
:files => [test_file] * 6,
|
||||
:autosort => false,
|
||||
:listeners => [@master_listener],
|
||||
:runner_listeners => [@runner_listener],
|
||||
:workers => [{
|
||||
:type => :ssh,
|
||||
:connect => 'localhost',
|
||||
:directory => remote_dir_path,
|
||||
:runners => 1
|
||||
capture_stderr do # redirect stderr
|
||||
@pid = Process.fork do
|
||||
Hydra::Master.new(
|
||||
:files => [test_file] * 6,
|
||||
:autosort => false,
|
||||
:listeners => [@master_listener],
|
||||
:runner_listeners => [@runner_listener],
|
||||
:workers => [{
|
||||
:type => :ssh,
|
||||
:connect => 'localhost',
|
||||
:directory => remote_dir_path,
|
||||
:runners => 1
|
||||
}],
|
||||
:verbose => false
|
||||
)
|
||||
:verbose => false
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -80,20 +80,22 @@ 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
|
||||
pid = Process.fork do
|
||||
runner = Hydra::Runner.new(:io => File.new('/dev/null', 'w'))
|
||||
runner.run_file(cucumber_feature_file)
|
||||
assert File.exists?(target_file)
|
||||
assert_equal "HYDRA", File.read(target_file)
|
||||
|
||||
FileUtils.rm_f(target_file)
|
||||
|
||||
runner.run_file(alternate_cucumber_feature_file)
|
||||
assert File.exists?(alternate_target_file)
|
||||
assert_equal "HYDRA", File.read(alternate_target_file)
|
||||
assert !File.exists?(target_file)
|
||||
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)
|
||||
assert File.exists?(target_file)
|
||||
assert_equal "HYDRA", File.read(target_file)
|
||||
|
||||
FileUtils.rm_f(target_file)
|
||||
|
||||
runner.run_file(alternate_cucumber_feature_file)
|
||||
assert File.exists?(alternate_target_file)
|
||||
assert_equal "HYDRA", File.read(alternate_target_file)
|
||||
assert !File.exists?(target_file)
|
||||
end
|
||||
Process.wait pid
|
||||
end
|
||||
Process.wait pid
|
||||
end
|
||||
|
||||
should "be able to run a runner over ssh" do
|
||||
|
@ -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