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
|
context "running a local worker" do
|
||||||
setup do
|
setup do
|
||||||
@pid = Process.fork do
|
capture_stderr do # redirect stderr
|
||||||
Hydra::Master.new(
|
@pid = Process.fork do
|
||||||
:files => [test_file] * 6,
|
Hydra::Master.new(
|
||||||
:autosort => false,
|
:files => [test_file] * 6,
|
||||||
:listeners => [@master_listener],
|
:autosort => false,
|
||||||
:runner_listeners => [@runner_listener],
|
:listeners => [@master_listener],
|
||||||
:verbose => false
|
:runner_listeners => [@runner_listener],
|
||||||
)
|
:verbose => false
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -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,20 +239,22 @@ 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
|
||||||
@pid = Process.fork do
|
capture_stderr do # redirect stderr
|
||||||
Hydra::Master.new(
|
@pid = Process.fork do
|
||||||
:files => [test_file] * 6,
|
Hydra::Master.new(
|
||||||
:autosort => false,
|
:files => [test_file] * 6,
|
||||||
:listeners => [@master_listener],
|
:autosort => false,
|
||||||
:runner_listeners => [@runner_listener],
|
:listeners => [@master_listener],
|
||||||
:workers => [{
|
:runner_listeners => [@runner_listener],
|
||||||
:type => :ssh,
|
:workers => [{
|
||||||
:connect => 'localhost',
|
:type => :ssh,
|
||||||
:directory => remote_dir_path,
|
:connect => 'localhost',
|
||||||
:runners => 1
|
:directory => remote_dir_path,
|
||||||
|
:runners => 1
|
||||||
}],
|
}],
|
||||||
:verbose => false
|
:verbose => false
|
||||||
)
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -80,20 +80,22 @@ 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
|
||||||
pid = Process.fork do
|
capture_stderr do # redirect stderr
|
||||||
runner = Hydra::Runner.new(:io => File.new('/dev/null', 'w'))
|
pid = Process.fork do
|
||||||
runner.run_file(cucumber_feature_file)
|
runner = Hydra::Runner.new(:io => File.new('/dev/null', 'w'))
|
||||||
assert File.exists?(target_file)
|
runner.run_file(cucumber_feature_file)
|
||||||
assert_equal "HYDRA", File.read(target_file)
|
assert File.exists?(target_file)
|
||||||
|
assert_equal "HYDRA", File.read(target_file)
|
||||||
FileUtils.rm_f(target_file)
|
|
||||||
|
FileUtils.rm_f(target_file)
|
||||||
runner.run_file(alternate_cucumber_feature_file)
|
|
||||||
assert File.exists?(alternate_target_file)
|
runner.run_file(alternate_cucumber_feature_file)
|
||||||
assert_equal "HYDRA", File.read(alternate_target_file)
|
assert File.exists?(alternate_target_file)
|
||||||
assert !File.exists?(target_file)
|
assert_equal "HYDRA", File.read(alternate_target_file)
|
||||||
|
assert !File.exists?(target_file)
|
||||||
|
end
|
||||||
|
Process.wait pid
|
||||||
end
|
end
|
||||||
Process.wait pid
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "be able to run a runner over ssh" do
|
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'
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user