Skip to content

Instantly share code, notes, and snippets.

@doxavore
Created December 11, 2013 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doxavore/7902806 to your computer and use it in GitHub Desktop.
Save doxavore/7902806 to your computer and use it in GitHub Desktop.
require 'spec_helper'
describe Celluloid::SupervisionGroup, actor_system: :global do
before :all do
class MyActor
include Celluloid
def running?; :yep; end
end
class MyGroup < Celluloid::SupervisionGroup
supervise MyActor, :as => :example
end
class MyParentGroup < Celluloid::SupervisionGroup
supervise MyGroup, :as => :my_group
end
end
it "runs applications" do
MyGroup.run!
sleep 0.01 # startup time hax
Celluloid::Actor[:example].should be_running
end
it "accepts a private actor registry" do
my_registry = Celluloid::Registry.new
MyGroup.run!(my_registry)
sleep 0.01
my_registry[:example].should be_running
end
it "removes actors from the registry when terminating" do
group = MyGroup.run!
group.terminate
Celluloid::Actor[:example].should be_nil
end
context "pool" do
before :all do
class MyActor
attr_reader :args
def initialize *args
@args = *args
end
end
class MyGroup
pool MyActor, :as => :example_pool, :args => 'foo', :size => 3
end
end
it "runs applications and passes pool options and actor args" do
MyGroup.run!
sleep 0.001 # startup time hax
Celluloid::Actor[:example_pool].should be_running
Celluloid::Actor[:example_pool].args.should eq ['foo']
Celluloid::Actor[:example_pool].size.should be 3
end
it "allows external access to the internal registry" do
supervisor = MyGroup.run!
supervisor[:example].should be_a MyActor
end
end
context "supervision group tree" do
it "starts child-supervised actors" do
MyParentGroup.run!
sleep 0.001
Celluloid::Actor[:example].should be_running
end
end
end
@doxavore
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment