Sha256: 2314fa756a7f7deaeaefaec0cb5d3cfd30d3780ef062925e34a1366f237a0bc5

Contents?: true

Size: 1.57 KB

Versions: 2

Compression:

Stored size: 1.57 KB

Contents

require 'spec_helper'

describe DCell::ActorProxy do
  before :all do
    @node = DCell::Node['test_node']
    @node.id.should == 'test_node'
    @remote_actor = @node[:test_actor]

    class LocalActor
      include Celluloid

      attr_reader :crash_reason
      trap_exit   :exit_handler

      def initialize
        @crash_reason = nil
      end

      def exit_handler(actor, reason)
        @crash_reason = reason
      end
    end
  end

  it "makes synchronous calls to remote actors" do
    @remote_actor.value.should == 42
  end

  it "makes future calls to remote actors" do
    @remote_actor.future(:value).value.should == 42
  end

  context :linking do
    before :each do
      @local_actor = LocalActor.new
    end

    it "links to remote actors" do
      @local_actor.link @remote_actor
      @local_actor.linked_to?(@remote_actor).should be_true
      @remote_actor.linked_to?(@local_actor).should be_true
    end

    it "unlinks from remote actors" do
      @local_actor.link @remote_actor
      @local_actor.unlink @remote_actor

      @local_actor.linked_to?(@remote_actor).should be_false
      @remote_actor.linked_to?(@local_actor).should be_false
    end

    it "traps exit messages from other actors" do
      @local_actor.link @remote_actor

      expect do
        @remote_actor.crash
      end.to raise_exception(RuntimeError)

      sleep 0.1 # hax to prevent a race between exit handling and the next call
      @local_actor.crash_reason.should be_a(RuntimeError)
      @local_actor.crash_reason.message.should == "the spec purposely crashed me :("
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dcell-0.13.0 spec/dcell/actor_proxy_spec.rb
dcell-0.13.0.pre spec/dcell/actor_proxy_spec.rb