Sha256: a43a2e2d6a70bc9d2851e368a3d5d74d09b116e0f7ba39e6ceb609000af51a32

Contents?: true

Size: 1.85 KB

Versions: 6

Compression:

Stored size: 1.85 KB

Contents

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

require 'drbqs/task/task'

describe DRbQS::Task::Generator do
  def check_task_ary(tasks, num, cl = DRbQS::Task)
    tasks.should have(num).items
    tasks.all? { |t| cl === t }.should be_true
  end

  subject { DRbQS::Task::Generator.new(:abc => 'ABC', :def => 123, :data => [1, 2, 3]) }

  it "should initialize instance varibles" do
    registrar = subject.instance_variable_get('@registrar')
    registrar.instance_variable_get('@abc').should == 'ABC'
    registrar.instance_variable_get('@def').should == 123
  end

  it "should create new tasks" do
    subject.set(:generate => 2) do |reg|
      @data.each do |i|
        reg.create_add(i, :to_s)
      end
    end
    subject.init
    check_task_ary(subject.new_tasks, 2)
    check_task_ary(subject.new_tasks, 1)
    subject.new_tasks.should be_nil
  end

  it "should should create task sets" do
    subject.set(:generate => 2, :collect => 10) do |reg|
      100.times do |i|
        reg.create_add(i, :to_s)
      end
    end
    subject.init
    5.times do |i|
      check_task_ary(subject.new_tasks, 2, DRbQS::Task::TaskSet)
    end
    subject.new_tasks.should be_nil
  end

  it "should debug generator" do
    subject.set(:generate => 2) do |reg|
      @data.each do |i|
        reg.create_add(i, :to_s)
      end
    end
    subject.init
    group_number, task_number = subject.debug_all_tasks
    group_number.should == 2
    task_number.should == 3
  end

  it "should wait" do
    subject.set(:generate => 2) do |reg|
      @data.each do |i|
        if i == 2
          reg.wait
        end
        create_add(i, :to_s)
      end
    end
    subject.init
    subject.waiting?.should be_false
    check_task_ary(subject.new_tasks, 1)
    subject.waiting?.should be_true
    check_task_ary(subject.new_tasks, 2)
    subject.waiting?.should be_false
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
drbqs-0.1.1 spec/task/task_generator_spec.rb
drbqs-0.1.0 spec/task/task_generator_spec.rb
drbqs-0.0.19 spec/task/task_generator_spec.rb
drbqs-0.0.18 spec/task/task_generator_spec.rb
drbqs-0.0.17 spec/task/task_generator_spec.rb
drbqs-0.0.16 spec/task/task_generator_spec.rb