ran runner test from both perspectives to ensure full coverage in the main thread
This commit is contained in:
parent
1518fb2e25
commit
7f1aff1967
|
@ -1,42 +1,70 @@
|
||||||
require File.join(File.dirname(__FILE__), 'test_helper')
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
||||||
|
|
||||||
class RunnerTest < Test::Unit::TestCase
|
TARGET = File.join(Dir.tmpdir, 'hydra_test.txt')
|
||||||
context "a test runner" do
|
TESTFILE = File.join(File.dirname(__FILE__), 'fixtures', 'write_file.rb')
|
||||||
setup do
|
|
||||||
@pipe = Hydra::Pipe.new
|
|
||||||
@child = Process.fork do
|
|
||||||
@pipe.identify_as_child
|
|
||||||
Hydra::Runner.new(@pipe)
|
|
||||||
end
|
|
||||||
@pipe.identify_as_parent
|
|
||||||
end
|
|
||||||
teardown do
|
|
||||||
@pipe.close
|
|
||||||
Process.wait(@child)
|
|
||||||
end
|
|
||||||
should "boot and run a file and shut down" do
|
|
||||||
assert @pipe.gets.is_a?(Hydra::Messages::Runner::RequestFile)
|
|
||||||
|
|
||||||
file = File.join(File.dirname(__FILE__), 'fixtures', 'assert_true.rb')
|
class RunnerTest < Test::Unit::TestCase
|
||||||
@pipe.write(Hydra::Messages::Runner::RunFile.new(:file => file))
|
context "with a file to test and a destination to verify" do
|
||||||
response = @pipe.gets
|
setup do
|
||||||
assert response.is_a?(Hydra::Messages::Runner::Results)
|
FileUtils.rm_f(TARGET)
|
||||||
assert response.output =~ /Finished/
|
|
||||||
assert_equal file, response.file
|
|
||||||
@pipe.write(Hydra::Messages::Runner::Shutdown.new)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
teardown do
|
||||||
|
FileUtils.rm_f(TARGET)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
should "run a test" do
|
should "run a test" do
|
||||||
target = File.join(Dir.tmpdir, 'hydra_test.txt')
|
# flip it around to the parent is in the fork, this gives
|
||||||
FileUtils.rm_f(target)
|
# us more direct control over the runner and proper test
|
||||||
assert !File.exists?(target)
|
# coverage output
|
||||||
file = File.join(File.dirname(__FILE__), 'fixtures', 'write_file.rb')
|
@pipe = Hydra::Pipe.new
|
||||||
assert @pipe.gets.is_a?(Hydra::Messages::Runner::RequestFile)
|
@parent = Process.fork do
|
||||||
@pipe.write(Hydra::Messages::Runner::RunFile.new(:file => file))
|
request_a_file_and_verify_completion(@pipe)
|
||||||
response = @pipe.gets
|
end
|
||||||
@pipe.write(Hydra::Messages::Runner::Shutdown.new)
|
run_the_runner(@pipe)
|
||||||
assert File.exists?(target)
|
Process.wait(@parent)
|
||||||
assert_equal "HYDRA", File.read(target)
|
end
|
||||||
|
|
||||||
|
# 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
|
||||||
|
@pipe = Hydra::Pipe.new
|
||||||
|
@child = Process.fork do
|
||||||
|
run_the_runner(@pipe)
|
||||||
|
end
|
||||||
|
request_a_file_and_verify_completion(@pipe)
|
||||||
|
Process.wait(@child)
|
||||||
end
|
end
|
||||||
end
|
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)
|
||||||
|
pipe.write(Hydra::Messages::Runner::RunFile.new(:file => TESTFILE))
|
||||||
|
|
||||||
|
# grab its response. This makes us wait for it to finish
|
||||||
|
response = pipe.gets
|
||||||
|
|
||||||
|
# tell it to shut down
|
||||||
|
pipe.write(Hydra::Messages::Runner::Shutdown.new)
|
||||||
|
|
||||||
|
# ensure it ran
|
||||||
|
assert File.exists?(TARGET)
|
||||||
|
assert_equal "HYDRA", File.read(TARGET)
|
||||||
|
|
||||||
|
pipe.close
|
||||||
|
end
|
||||||
|
|
||||||
|
def run_the_runner(pipe)
|
||||||
|
pipe.identify_as_child
|
||||||
|
Hydra::Runner.new(pipe)
|
||||||
|
pipe.close
|
||||||
|
end
|
||||||
|
end
|
||||||
|
include RunnerTestHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue