Sha256: 28ec1cf5ca744f89222719500b64b14db8051666a64aef99397fc03d693e435a

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

require 'test/unit'
require 'securerandom'
require 'rubygems'
require_relative "#{File.dirname(__FILE__)}/../../lib/pigato.rb"

class BaseTest < Test::Unit::TestCase

  def setup
    bhost = 'tcp://localhost:55555'
    @client = Pigato::Client.new(bhost, { :autostart => true })
    @ns = SecureRandom.uuid
    
    @wks = []    
    @wks << fork do
      worker = Pigato::Worker.new(bhost, @ns + 'echo')

      loop do
        reply = nil
        request = worker.recv reply
        worker.reply request
      end
    end

    @wks << fork do
      worker = Pigato::Worker.new(bhost, @ns + 'empty')

      loop do
        reply = nil
        request = worker.recv reply
        worker.reply nil
      end
    end
  end

  def teardown
    @wks.each do |wk|
      Process.kill 9, wk
      Process.wait wk
    end
  end

  def test0
    assert_equal('hello', @client.request(@ns + 'echo', 'hello'))
    h = { 'hello' => 'world' }
    assert_equal(h, @client.request(@ns + 'echo', h))
    a = ['a', 1, false]
    assert_equal(a, @client.request(@ns + 'echo', a))
    
    assert_equal(nil, @client.request(@ns + 'empty', nil))
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pigato-0.2.5 tests/test_base.rb
pigato-0.2.4 tests/test_base.rb
pigato-0.2.3 tests/test_base.rb