runner now runs test files when asked. but it does it the dumb way
This commit is contained in:
parent
39ba34539a
commit
200016994b
|
@ -40,5 +40,5 @@ module Hydra #:nodoc:
|
|||
end
|
||||
end
|
||||
|
||||
require 'hydra/message/runner_requests_file'
|
||||
require 'hydra/message/runner_messages'
|
||||
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
module Hydra #:nodoc:
|
||||
module Messages #:nodoc:
|
||||
module Runner #:nodoc:
|
||||
# Message indicating that a Runner needs a file to run
|
||||
class RequestFile < Hydra::Message
|
||||
end
|
||||
|
||||
# Message telling the Runner to run a file
|
||||
class RunFile < Hydra::Message
|
||||
attr_accessor :file
|
||||
def serialize #:nodoc:
|
||||
super(:file => @file)
|
||||
end
|
||||
def handle(runner) #:nodoc:
|
||||
runner.run_file(@file)
|
||||
end
|
||||
end
|
||||
|
||||
# Message for the Runner to respond with its results
|
||||
class Results < Hydra::Message
|
||||
attr_accessor :output
|
||||
attr_accessor :file
|
||||
def serialize #:nodoc:
|
||||
super(:output => @output, :file => @file)
|
||||
end
|
||||
end
|
||||
|
||||
# Message to tell the Runner to shut down
|
||||
class Shutdown < Hydra::Message
|
||||
def handle(runner) #:nodoc:
|
||||
runner.stop
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
module Hydra #:nodoc:
|
||||
module Messages #:nodoc:
|
||||
# Message indicating that a Runner needs a file to run
|
||||
class RunnerRequestsFile < Hydra::Message
|
||||
end
|
||||
end
|
||||
end
|
|
@ -5,7 +5,28 @@ module Hydra #:nodoc:
|
|||
# parent) to send it messages on which files to execute.
|
||||
def initialize(io)
|
||||
@io = io
|
||||
@io.write Hydra::Messages::RunnerRequestsFile.new
|
||||
@io.write Hydra::Messages::Runner::RequestFile.new
|
||||
process_messages
|
||||
end
|
||||
|
||||
# The runner will continually read messages and handle them.
|
||||
def process_messages
|
||||
@running = true
|
||||
while @running
|
||||
message = @io.gets
|
||||
message.handle(self) if message
|
||||
end
|
||||
end
|
||||
|
||||
# Run a test file and report the results
|
||||
def run_file(file)
|
||||
`ruby #{file}`
|
||||
@io.write Hydra::Messages::Runner::Results.new(:output => "Finished", :file => file)
|
||||
end
|
||||
|
||||
# Stop running
|
||||
def stop
|
||||
@running = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require 'rubygems'
|
||||
require 'test/unit'
|
||||
require 'shoulda'
|
||||
require 'tmpdir'
|
||||
|
||||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
||||
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
require File.join(File.dirname(__FILE__), '..', 'helper')
|
||||
|
||||
class TestAssertTrue < Test::Unit::TestCase
|
||||
should "be true" do
|
||||
assert true
|
||||
end
|
||||
end
|
|
@ -0,0 +1,10 @@
|
|||
require File.join(File.dirname(__FILE__), '..', 'helper')
|
||||
|
||||
class TestWriteFile < Test::Unit::TestCase
|
||||
should "write file" do
|
||||
File.open(File.join(Dir.tmpdir, 'hydra_test.txt'), 'w') do |f|
|
||||
f.write "HYDRA"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -17,8 +17,8 @@ class TestMessage < Test::Unit::TestCase
|
|||
end
|
||||
should "serialize" do
|
||||
assert_equal(
|
||||
"{:class=>TestMessage::MyMessage, :my_var=>\"my value\"}",
|
||||
@m.serialize
|
||||
{:class=>TestMessage::MyMessage, :my_var=>"my value"},
|
||||
eval(@m.serialize)
|
||||
)
|
||||
end
|
||||
should "build from serialization" do
|
||||
|
|
|
@ -11,14 +11,32 @@ class TestRunner < Test::Unit::TestCase
|
|||
@pipe.identify_as_parent
|
||||
end
|
||||
teardown do
|
||||
@pipe.close
|
||||
Process.wait(@child)
|
||||
end
|
||||
should "request a file on boot" do
|
||||
assert @pipe.gets.is_a?(Hydra::Messages::RunnerRequestsFile)
|
||||
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__), 'sample_tests', 'assert_true.rb')
|
||||
@pipe.write(Hydra::Messages::Runner::RunFile.new(:file => file))
|
||||
response = @pipe.gets
|
||||
assert response.is_a?(Hydra::Messages::Runner::Results)
|
||||
assert response.output =~ /Finished/
|
||||
assert_equal file, response.file
|
||||
@pipe.write(Hydra::Messages::Runner::Shutdown.new)
|
||||
end
|
||||
should "return a result message after processing a file" do
|
||||
|
||||
|
||||
should "run a test" do
|
||||
target = File.join(Dir.tmpdir, 'hydra_test.txt')
|
||||
FileUtils.rm_f(target)
|
||||
assert !File.exists?(target)
|
||||
file = File.join(File.dirname(__FILE__), 'sample_tests', 'write_file.rb')
|
||||
assert @pipe.gets.is_a?(Hydra::Messages::Runner::RequestFile)
|
||||
@pipe.write(Hydra::Messages::Runner::RunFile.new(:file => file))
|
||||
response = @pipe.gets
|
||||
@pipe.write(Hydra::Messages::Runner::Shutdown.new)
|
||||
assert File.exists?(target)
|
||||
assert_equal "HYDRA", File.read(target)
|
||||
end
|
||||
should "terminate when sent a shutdown message"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue