2011-08-23 11:01:48 +00:00
|
|
|
require 'test_helper'
|
2010-01-26 18:50:44 +00:00
|
|
|
|
2010-01-28 15:30:18 +00:00
|
|
|
class PipeTest < Test::Unit::TestCase
|
2010-01-26 18:50:44 +00:00
|
|
|
context "a pipe" do
|
|
|
|
setup do
|
|
|
|
@pipe = Hydra::Pipe.new
|
|
|
|
end
|
2010-01-27 20:57:26 +00:00
|
|
|
teardown do
|
|
|
|
@pipe.close
|
|
|
|
end
|
2010-01-26 18:50:44 +00:00
|
|
|
should "be able to write messages" do
|
2010-01-27 20:19:48 +00:00
|
|
|
child = Process.fork do
|
2010-01-26 18:50:44 +00:00
|
|
|
@pipe.identify_as_child
|
2010-01-27 20:19:48 +00:00
|
|
|
assert_equal "Test Message", @pipe.gets.text
|
|
|
|
@pipe.write Hydra::Messages::TestMessage.new(:text => "Message Received")
|
|
|
|
@pipe.write Hydra::Messages::TestMessage.new(:text => "Second Message")
|
2010-01-26 18:50:44 +00:00
|
|
|
end
|
|
|
|
@pipe.identify_as_parent
|
2010-01-27 20:19:48 +00:00
|
|
|
@pipe.write Hydra::Messages::TestMessage.new(:text => "Test Message")
|
|
|
|
assert_equal "Message Received", @pipe.gets.text
|
|
|
|
assert_equal "Second Message", @pipe.gets.text
|
2010-01-27 20:57:26 +00:00
|
|
|
Process.wait(child) #ensure it quits, so there is nothing to write to
|
2010-01-27 20:19:48 +00:00
|
|
|
assert_raise IOError do
|
|
|
|
@pipe.write Hydra::Messages::TestMessage.new(:text => "anyone there?")
|
2010-01-26 18:50:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
should "not allow writing if unidentified" do
|
2010-01-27 20:19:48 +00:00
|
|
|
assert_raise IOError do
|
|
|
|
@pipe.write Hydra::Messages::TestMessage.new(:text => "Test Message")
|
2010-01-26 18:50:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
should "not allow reading if unidentified" do
|
2010-01-27 20:19:48 +00:00
|
|
|
assert_raise IOError do
|
2010-01-26 18:50:44 +00:00
|
|
|
@pipe.gets
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|