Sha256: b48bac3966f949479f3936ed9529094c2926dc676e7ec3da29bdaf4c9253c122

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "Tpool" do
  it "should work" do
    errs = []
    
    tp = Tpool.new(
      :threads => 4,
      :priority => -3,
      :on_error => lambda{|data|
        errs << data[:error]
      }
    )
    
    res = tp.run do
      errs << "Expected thread priority to be -3 but it wasnt: '#{Thread.current.priority}'." if Thread.current.priority != -3
      "kasper"
    end
    
    raise errs.first if !errs.empty?
    raise "Expected result to be 'kasper' but it wasnt: '#{res}'." if res != "kasper"
    
    
    blk = tp.run_async do
      "kasper"
    end
    blk.join
    
    raise "Expected result to be 'kasper' but it wasnt: '#{res}'." if res != "kasper"
    
    
    
    blk = tp.run_async do
      sleep 5
      "kasper"
    end
    
    blk.kill
    
    error = false
    begin
      blk.error!
    rescue Exception
      error = true
    end
    
    raise "Expected error but didnt get one." if !error
    
    raise errs.first if !errs.empty?
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tpool-0.0.4 spec/tpool_spec.rb
tpool-0.0.3 spec/tpool_spec.rb
tpool-0.0.2 spec/tpool_spec.rb