Sha256: ce473776992facd57b04d3b210b9b0aa3e0260d1734475ac1fd805ee6a27fd01

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

require 'spec_helper'

describe "Celluloid.pool" do
  class ExampleError < StandardError; end

  class MyWorker
    include Celluloid

    def process(queue = nil)
      if queue
        queue << :done
      else
        :done
      end
    end

    def crash
      raise ExampleError, "zomgcrash"
    end
  end

  subject { MyWorker.pool }

  it "processes work units synchronously" do
    subject.process.should be :done
  end

  it "processes work units asynchronously" do
    queue = Queue.new
    subject.async.process(queue)
    queue.pop.should be :done
  end

  it "handles crashes" do
    expect { subject.crash }.to raise_error(ExampleError)
    subject.process.should be :done
  end

  it "uses a fixed-sized number of threads" do
    subject # eagerly evaluate the pool to spawn it

    actors = Celluloid::Actor.all
    100.times.map { subject.future(:process) }.map(&:value)

    new_actors = Celluloid::Actor.all - actors
    new_actors.should eq []
  end

  it "terminates" do
    expect { subject.terminate }.to_not raise_exception
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
celluloid-0.15.0 spec/celluloid/pool_spec.rb
celluloid-0.15.0.pre2 spec/celluloid/pool_spec.rb
celluloid-0.15.0.pre spec/celluloid/pool_spec.rb