Sha256: 07d9085b5258b92ac64810cf601fdf75b93c07e68f5440b4f52d999b1ab07193

Contents?: true

Size: 1.2 KB

Versions: 15

Compression:

Stored size: 1.2 KB

Contents

require 'spec_helper'

describe Celluloid::InternalPool do
  it "gets threads from the pool" do
    subject.get { sleep 1 }.should be_a Thread
  end

  it "puts threads back into the pool" do
    subject.idle_size.should be_zero
    subject.busy_size.should be_zero

    queue = Queue.new
    subject.get { queue.pop }

    subject.idle_size.should be_zero
    subject.busy_size.should eq 1

    queue << nil
    sleep 0.01 # hax

    subject.idle_size.should eq 1
    subject.busy_size.should eq 0
  end

  it "cleans thread locals from old threads" do
    thread = subject.get { Thread.current[:foo] = :bar }

    sleep 0.01 #hax
    thread[:foo].should be_nil
  end

  it "doesn't fail if a third-party thread is spawned" do
    subject.idle_size.should be_zero
    subject.busy_size.should be_zero

    subject.get { ::Thread.new { sleep 0.5 } }.should be_a(Celluloid::Thread)

    sleep 0.01 # hax

    subject.idle_size.should eq 1
    subject.busy_size.should eq 0
  end

  it "doesn't leak dead threads" do
    subject.max_idle = 0 # Instruct the pool to immediately shut down the thread.
    subject.get { true }.should be_a(Celluloid::Thread)

    sleep 0.01 # hax

    subject.to_a.should have(0).items
  end
end

Version data entries

15 entries across 13 versions & 5 rubygems

Version Path
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/celluloid-0.16.0/spec/celluloid/internal_pool_spec.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/celluloid-0.16.0/spec/celluloid/internal_pool_spec.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/celluloid-0.16.0/spec/celluloid/internal_pool_spec.rb
scoot-0.0.4 .bundle/gems/ruby/2.2.0/gems/celluloid-0.16.0/spec/celluloid/internal_pool_spec.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/celluloid-0.16.0/spec/celluloid/internal_pool_spec.rb
celluloid-0.16.0 spec/celluloid/internal_pool_spec.rb
celluloid-0.16.0.pre3 spec/celluloid/internal_pool_spec.rb
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/gems/celluloid-0.15.2/spec/celluloid/internal_pool_spec.rb
celluloid-0.16.0.pre2 spec/celluloid/internal_pool_spec.rb
celluloid-0.16.0.pre spec/celluloid/internal_pool_spec.rb
celluloid-0.15.2 spec/celluloid/internal_pool_spec.rb
celluloid-0.15.1 spec/celluloid/internal_pool_spec.rb
celluloid-0.15.0 spec/celluloid/internal_pool_spec.rb
celluloid-0.15.0.pre2 spec/celluloid/internal_pool_spec.rb
celluloid-0.15.0.pre spec/celluloid/internal_pool_spec.rb