/usr/lib/ruby/vendor_ruby/celluloid/rspec/mailbox_examples.rb is in ruby-celluloid 0.16.0-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | shared_context "a Celluloid Mailbox" do
after do
allow(Celluloid.logger).to receive(:debug)
subject.shutdown if subject.alive?
end
it "receives messages" do
message = :ohai
subject << message
expect(subject.receive).to eq(message)
end
it "prioritizes system events over other messages" do
subject << :dummy1
subject << :dummy2
subject << Celluloid::SystemEvent.new
expect(subject.receive).to 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
expect(subject.receive { |msg| msg.is_a? Foo }).to eq(foo)
expect(subject.receive { |msg| msg.is_a? Bar }).to eq(bar)
expect(subject.receive).to eq(baz)
end
it "waits for a given timeout interval" do
interval = 0.1
started_at = Time.now
expect do
subject.receive(interval) { false }
end.to raise_exception(Celluloid::TimeoutError)
expect(Time.now - started_at).to be_within(Celluloid::TIMER_QUANTUM).of interval
end
it "has a size" do
expect(subject).to respond_to(:size)
expect(subject.size).to be_zero
subject << :foo
subject << :foo
expect(subject.entries.size).to eq(2)
end
it "discards messages received when when full" do
subject.max_size = 2
subject << :first
subject << :second
subject << :third
expect(subject.to_a).to match_array([:first, :second])
end
it "logs discarded messages" do
expect(Celluloid.logger).to receive(:debug).with("Discarded message (mailbox is dead): third")
subject.max_size = 2
subject << :first
subject << :second
subject << :third
end
it "discard messages when dead" do
expect(Celluloid.logger).to receive(:debug).with("Discarded message (mailbox is dead): first")
expect(Celluloid.logger).to receive(:debug).with("Discarded message (mailbox is dead): second")
expect(Celluloid.logger).to receive(:debug).with("Discarded message (mailbox is dead): third")
subject << :first
subject << :second
subject.shutdown
subject << :third
end
end
|