2010-01-28 15:30:18 +00:00
|
|
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2010-01-27 16:38:11 +00:00
|
|
|
|
2010-01-28 15:30:18 +00:00
|
|
|
class RunnerTest < Test::Unit::TestCase
|
2010-01-28 16:01:54 +00:00
|
|
|
context "with a file to test and a destination to verify" do
|
2010-01-27 16:38:11 +00:00
|
|
|
setup do
|
2010-01-29 19:56:02 +00:00
|
|
|
FileUtils.rm_f(target_file)
|
2010-01-28 16:01:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
teardown do
|
2010-01-29 19:56:02 +00:00
|
|
|
FileUtils.rm_f(target_file)
|
2010-01-28 16:01:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
should "run a test" do
|
|
|
|
# flip it around to the parent is in the fork, this gives
|
|
|
|
# us more direct control over the runner and proper test
|
|
|
|
# coverage output
|
2010-01-28 21:52:11 +00:00
|
|
|
pipe = Hydra::Pipe.new
|
|
|
|
parent = Process.fork do
|
|
|
|
request_a_file_and_verify_completion(pipe)
|
2010-01-27 16:38:11 +00:00
|
|
|
end
|
2010-01-28 21:52:11 +00:00
|
|
|
run_the_runner(pipe)
|
|
|
|
Process.wait(parent)
|
2010-01-27 16:38:11 +00:00
|
|
|
end
|
2010-01-28 16:01:54 +00:00
|
|
|
|
|
|
|
# this flips the above test, so that the main process runs a bit of the parent
|
|
|
|
# code, but only with minimal assertion
|
|
|
|
should "be able to tell a runner to run a test" do
|
2010-01-28 21:52:11 +00:00
|
|
|
pipe = Hydra::Pipe.new
|
|
|
|
child = Process.fork do
|
|
|
|
run_the_runner(pipe)
|
2010-01-28 16:01:54 +00:00
|
|
|
end
|
2010-01-28 21:52:11 +00:00
|
|
|
request_a_file_and_verify_completion(pipe)
|
|
|
|
Process.wait(child)
|
2010-01-27 20:57:26 +00:00
|
|
|
end
|
2010-01-28 16:01:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
module RunnerTestHelper
|
|
|
|
def request_a_file_and_verify_completion(pipe)
|
|
|
|
pipe.identify_as_parent
|
|
|
|
|
|
|
|
# make sure it asks for a file, then give it one
|
|
|
|
assert pipe.gets.is_a?(Hydra::Messages::Runner::RequestFile)
|
2010-01-29 19:56:02 +00:00
|
|
|
pipe.write(Hydra::Messages::Worker::RunFile.new(:file => test_file))
|
2010-01-28 16:01:54 +00:00
|
|
|
|
|
|
|
# grab its response. This makes us wait for it to finish
|
|
|
|
response = pipe.gets
|
|
|
|
|
|
|
|
# tell it to shut down
|
2010-01-29 18:30:25 +00:00
|
|
|
pipe.write(Hydra::Messages::Worker::Shutdown.new)
|
2010-01-28 16:01:54 +00:00
|
|
|
|
|
|
|
# ensure it ran
|
2010-01-29 19:56:02 +00:00
|
|
|
assert File.exists?(target_file)
|
|
|
|
assert_equal "HYDRA", File.read(target_file)
|
2010-01-27 16:38:11 +00:00
|
|
|
end
|
2010-01-27 22:19:32 +00:00
|
|
|
|
2010-01-28 16:01:54 +00:00
|
|
|
def run_the_runner(pipe)
|
|
|
|
pipe.identify_as_child
|
2010-01-29 18:01:53 +00:00
|
|
|
Hydra::Runner.new({:io => pipe})
|
2010-01-27 20:19:48 +00:00
|
|
|
end
|
2010-01-27 16:38:11 +00:00
|
|
|
end
|
2010-01-28 16:01:54 +00:00
|
|
|
include RunnerTestHelper
|
2010-01-27 16:38:11 +00:00
|
|
|
end
|
2010-01-28 16:01:54 +00:00
|
|
|
|