1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
require 'spec_helper.rb'
RSpec.describe Celluloid::Actor::System do
class TestActor
include Celluloid
def identity
:testing
end
end
after do
subject.shutdown
end
it "supports non-global Actor::System" do
subject.within do
expect(Celluloid.actor_system).to eq(subject)
end
end
it "makes actors accessible by Celluloid[:actor]" do
subject.start
subject.within do
TestActor.supervise as: :testing, type: TestActor
expect(subject.registered).to include(:testing)
expect(Celluloid::Actor[:testing].identity).to eq(:testing)
end
end
it "starts default actors" do
subject.start
expect(subject.registered).to eq(Celluloid::Actor::System::ROOT_SERVICES.map { |r| r[:as] })
end
it "support getting threads" do
queue = Queue.new
subject.get_thread do
expect(Celluloid.actor_system).to eq(subject)
queue << nil
end
queue.pop
end
it "allows a stack dump" do
expect(subject.stack_dump).to be_a(Celluloid::Internals::Stack::Dump)
end
it "allows a stack summary" do
expect(subject.stack_summary).to be_a(Celluloid::Internals::Stack::Summary)
end
it "returns named actors" do
subject.start
subject.within do
TestActor.supervise as: :test
end
expect(subject.registered).to include(:test)
end
it "returns running actors" do
expect(subject.running).to be_empty
first = subject.within do
TestActor.new
end
second = subject.within do
TestActor.new
end
expect(subject.running).to eq([first, second])
end
it "shuts down" do
subject.shutdown
expect { subject.get_thread }
.to raise_error(Celluloid::NotActive)
end
it "warns nicely when no actor system is started" do
expect { TestActor.new }
.to raise_error("Celluloid is not yet started; use Celluloid.boot")
end
end
|