finished messaging system for ssh and pipes

This commit is contained in:
Nick Gauthier 2010-01-27 15:57:26 -05:00
parent 2fa15b735b
commit 3414ee5c20
4 changed files with 16 additions and 1 deletions

View File

@ -19,6 +19,11 @@ module Hydra #:nodoc:
end
end
def close
@reader.close if @reader
@writer.close if @writer
end
class UnprocessableMessage < RuntimeError
attr_accessor :message
def initialize(message = "Message expected")

View File

@ -5,6 +5,9 @@ class TestPipe < Test::Unit::TestCase
setup do
@pipe = Hydra::Pipe.new
end
teardown do
@pipe.close
end
should "be able to write messages" do
child = Process.fork do
@pipe.identify_as_child
@ -16,6 +19,7 @@ class TestPipe < Test::Unit::TestCase
@pipe.write Hydra::Messages::TestMessage.new(:text => "Test Message")
assert_equal "Message Received", @pipe.gets.text
assert_equal "Second Message", @pipe.gets.text
Process.wait(child) #ensure it quits, so there is nothing to write to
assert_raise IOError do
@pipe.write Hydra::Messages::TestMessage.new(:text => "anyone there?")
end

View File

@ -4,12 +4,15 @@ class TestRunner < Test::Unit::TestCase
context "a test runner" do
setup do
@pipe = Hydra::Pipe.new
Process.fork do
@child = Process.fork do
@pipe.identify_as_child
Hydra::Runner.new(@pipe)
end
@pipe.identify_as_parent
end
teardown do
Process.wait(@child)
end
should "request a file on boot" do
assert @pipe.gets.is_a?(Hydra::Messages::RunnerRequestsFile)
end

View File

@ -10,6 +10,9 @@ class TestSSH < Test::Unit::TestCase
)
@message = Hydra::Messages::TestMessage.new
end
teardown do
@ssh.close
end
should "be able to execute a command" do
@ssh.write @message
assert_equal @message.text, @ssh.gets.text