Sha256: 030a6c5e39d161c3e72a49a738e8bb00e4082539524aefe22eb2a68a0a537b0b

Contents?: true

Size: 1.54 KB

Versions: 6

Compression:

Stored size: 1.54 KB

Contents

shared_context "a Celluloid Mailbox" do
  it "receives messages" do
    message = :ohai

    subject << message
    subject.receive.should == message
  end

  it "prioritizes system events over other messages" do
    subject << :dummy1
    subject << :dummy2

    subject << Celluloid::SystemEvent.new
    subject.receive.should be_a(Celluloid::SystemEvent)
  end

  it "selectively receives messages with a block" do
    class Foo; end
    class Bar; end
    class Baz; end

    foo, bar, baz = Foo.new, Bar.new, Baz.new

    subject << baz
    subject << foo
    subject << bar

    subject.receive { |msg| msg.is_a? Foo }.should eq(foo)
    subject.receive { |msg| msg.is_a? Bar }.should eq(bar)
    subject.receive.should eq(baz)
  end

  it "waits for a given timeout interval" do
    interval = 0.1
    started_at = Time.now

    subject.receive(interval) { false }
    (Time.now - started_at).should be_within(Celluloid::TIMER_QUANTUM).of interval
  end

  it "has a size" do
    subject.should respond_to(:size)
    subject.size.should be_zero
    subject << :foo
    subject << :foo
    subject.size.should be 2
  end

  it "discards messages received when when full" do
    subject.max_size = 2
    subject << :first
    subject << :second
    subject << :third
    subject.to_a.should =~ [:first, :second]
  end

  it "logs discarded messages" do
    Celluloid.logger = mock.as_null_object
    Celluloid.logger.should_receive(:debug).with("Discarded message: third")

    subject.max_size = 2
    subject << :first
    subject << :second
    subject << :third
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
celluloid-0.14.1 spec/support/mailbox_examples.rb
celluloid-0.14.1.pre spec/support/mailbox_examples.rb
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/celluloid-0.14.0/spec/support/mailbox_examples.rb
sidekiq-statsd-0.1.0 vendor/ruby/1.9.1/gems/celluloid-0.14.0/spec/support/mailbox_examples.rb
celluloid-0.14.0 spec/support/mailbox_examples.rb
celluloid-0.14.0.pre spec/support/mailbox_examples.rb