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
|
require 'spec_helper'
describe Celluloid::InternalPool do
it "gets threads from the pool" do
expect(subject.get { sleep 1 }).to be_a Thread
end
it "puts threads back into the pool" do
expect(subject.idle_size).to be_zero
expect(subject.busy_size).to be_zero
queue = Queue.new
subject.get { queue.pop }
expect(subject.idle_size).to be_zero
expect(subject.busy_size).to eq 1
queue << nil
sleep 0.01 # hax
expect(subject.idle_size).to eq 1
expect(subject.busy_size).to eq 0
end
it "cleans thread locals from old threads" do
thread = subject.get { Thread.current[:foo] = :bar }
sleep 0.01 #hax
expect(thread[:foo]).to be_nil
end
it "doesn't fail if a third-party thread is spawned" do
expect(subject.idle_size).to be_zero
expect(subject.busy_size).to be_zero
expect(subject.get { ::Thread.new { sleep 0.5 } }).to be_a(Celluloid::Thread)
sleep 0.01 # hax
expect(subject.idle_size).to eq 1
expect(subject.busy_size).to eq 0
end
it "doesn't leak dead threads" do
subject.max_idle = 0 # Instruct the pool to immediately shut down the thread.
expect(subject.get { true }).to be_a(Celluloid::Thread)
sleep 0.01 # hax
expect(subject.to_a.size).to eq(0)
end
end
|