Sha256: 079a09026e4ab792f42cd3b483e2d1261eda87b438ed0f36887b3c6a85dbf9dd

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

require 'rubygems'
require "lib/ass"
require "spec"
require 'rant/spec'
require 'thread'

require 'eventmachine'
EM.threadpool_size = 1

describe "RPC" do
  before do
    q = Queue.new
    @server = nil
    @thread = Thread.new {ASS.start(:logging => false) {
        q << :ready
      }}
    @thread.abort_on_exception = true
    q.pop.should == :ready
  end

  after do
    ASS.stop
    @thread.join
  end

  it "should make synchronized call" do
    ASS.actor("spec") {
      def foo(i)
        i
      end
    }
    rpc = ASS.rpc
    futures = 100.times.map { |i| rpc.call("spec",:foo,i) }
    rspec_thread = Thread.current
    futures.each_with_index { |f,i|
      f.should be_an(ASS::RPC::Future)
      f.wait(5) {
        raise "timeout"
      }.should == i
      f.done?.should == true
      f.timeout?.should == false
    }
  end

  it "should timeout call" do
    ASS.actor("spec") {
      def foo(i)
        discard
      end
    }
    rpc = ASS.rpc
    rpc.call("spec",:foo,1).wait(1) { :timeout }.should == :timeout
  end

  it "should make call information available to waited future" do
    ASS.actor("spec") {
      def foo(i)
        i
      end
    }
    rpc = ASS.rpc
    futures = 10.times.map { |i| rpc.call("spec",:foo,i,{},i) }
    futures.each_with_index { |f,i|
      f.wait(5) {
        raise "timeout"
      }
      f.header.should be_a(MQ::Header)
      f.method.should == :foo
      f.meta.should == i
      f.data.should == i
    }
  end
  
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
ASS-0.1.0 spec/rpc_spec.rb
jamesgolick-ASS-0.1.0 spec/rpc_spec.rb