File: container_spec.rb

package info (click to toggle)
ruby-celluloid 0.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 848 kB
  • sloc: ruby: 7,579; makefile: 10
file content (72 lines) | stat: -rw-r--r-- 1,841 bytes parent folder | download
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
RSpec.describe Celluloid::Supervision::Container, actor_system: :global do
  let(:queue_count) { 1 }

  before do
    SupervisionContainerHelper.reset!
    subject # init for easier debugging
    queue_count.times { SupervisionContainerHelper.pop! }
  end

  after do
    # TODO: hangs without condition on JRuby?
    subject.terminate if subject.alive?
  end

  context "when supervising a single actor" do
    subject do
      Class.new(Celluloid::Supervision::Container) do
        supervise type: MyContainerActor, as: :example
      end.run!(*registry)
    end

    let(:registry) { [] }

    it "runs applications" do
      expect(Celluloid::Actor[:example]).to be_running
    end

    context "with a private registry" do
      let(:registry) { Celluloid::Internals::Registry.new }

      it "accepts a private actor registry" do
        expect(registry[:example]).to be_running
      end
    end

    it "removes actors from the registry when terminating" do
      subject.terminate
      expect(Celluloid::Actor[:example]).to be_nil
    end

    it "allows external access to the internal registry" do
      expect(subject[:example]).to be_a MyContainerActor
    end
  end

  context "with multiple args" do
    subject do
      Class.new(Celluloid::Supervision::Container) do
        supervise type: MyContainerActor, as: :example, args: %i[foo bar]
      end.run!
    end

    it "passes them" do
      expect(Celluloid::Actor[:example].args).to eq(%i[foo bar])
    end
  end

  context "with lazy evaluation" do
    subject do
      Class.new(Celluloid::Supervision::Container) do
        supervise type: MyContainerActor, as: :example, args: -> { :lazy }
      end.run!
    end

    it "evaluates correctly" do
      expect(Celluloid::Actor[:example].args).to eq([:lazy])
    end
  end

  xit("can remove members") do
  end
end