Sha256: 49d45b34d249a541e87a2db68bc121edc0216835c5ee00477ece13f852771aa1

Contents?: true

Size: 1.53 KB

Versions: 12

Compression:

Stored size: 1.53 KB

Contents

require 'spec_helper'

describe ZK::Threadpool do

  before do
    @threadpool = ZK::Threadpool.new
  end

  after do
    @threadpool.shutdown
  end

  describe :new do
    it %[should be running] do
      @threadpool.should be_running
    end

    it %[should use the default size] do
      @threadpool.size.should == ZK::Threadpool.default_size
    end
  end


  describe :defer do
    it %[should run the given block on a thread in the threadpool] do
      @th = nil

      @threadpool.defer { @th = Thread.current }

      wait_until(2) { @th }

      @th.should_not == Thread.current
    end

    it %[should barf if the argument is not callable] do
      bad_obj = flexmock(:not_callable)
      bad_obj.should_not respond_to(:call)

      lambda { @threadpool.defer(bad_obj) }.should raise_error(ArgumentError)
    end

    it %[should barf if the threadpool is not running] do
      @threadpool.shutdown
      lambda { @threadpool.defer { "hai!" } }.should raise_error(ZK::Exceptions::ThreadpoolIsNotRunningException)
    end
  end

  describe :shutdown do
    it %[should set running to false] do
      @threadpool.shutdown
      @threadpool.should_not be_running
    end
  end

  describe :start! do
    it %[should be able to start a threadpool that had previously been shutdown (reuse)] do
      @threadpool.shutdown
      @threadpool.start!.should be_true

      @threadpool.should be_running

      @rval = nil

      @threadpool.defer do 
        @rval = true
      end

      wait_until(2) { @rval }
      @rval.should be_true
    end
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
zk-0.9.1 spec/z_k/threadpool_spec.rb
zk-0.9.0 spec/z_k/threadpool_spec.rb
zk-0.8.9 spec/z_k/threadpool_spec.rb
zk-0.8.8 spec/z_k/threadpool_spec.rb
zk-0.8.7 spec/z_k/threadpool_spec.rb
zk-0.8.6 spec/z_k/threadpool_spec.rb
zk-0.8.5 spec/z_k/threadpool_spec.rb
zk-0.8.4 spec/z_k/threadpool_spec.rb
zk-0.8.3 spec/z_k/threadpool_spec.rb
zk-0.8.2 spec/z_k/threadpool_spec.rb
zk-0.8.1 spec/z_k/threadpool_spec.rb
zk-0.7.1 spec/z_k/threadpool_spec.rb