Sha256: 854dfcd519eef287b6b0ea6be23998a3602905cc4431f476ab0aefca38864614

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

require File.join(File.dirname(__FILE__), 'helper')

class TestPipe < Test::Unit::TestCase
  context "a pipe" do
    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
        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")
      end
      @pipe.identify_as_parent
      @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
    end
    should "not allow writing if unidentified" do
      assert_raise IOError do
        @pipe.write Hydra::Messages::TestMessage.new(:text => "Test Message")
      end
    end
    should "not allow reading if unidentified" do
      assert_raise IOError do
        @pipe.gets
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hydra-0.3.0 test/test_pipe.rb
hydra-0.2.0 test/test_pipe.rb