Sha256: c49a90abe24f7629ceddadd3f33e27d9cfb5201f5f0aa7135e3712ec2ba56c67

Contents?: true

Size: 1.34 KB

Versions: 16

Compression:

Stored size: 1.34 KB

Contents

require 'test_helper'

class WorkUnitTest < Test::Unit::TestCase

  context "A WorkUnit" do
    
    setup do
      @unit = CloudCrowd::WorkUnit.make
      @job = @unit.job
    end
    
    subject { @unit }
    
    should_belong_to :job
    
    should_validate_presence_of :job_id, :status, :input, :action
    
    should "know if its done" do
      assert !@unit.complete?
      @unit.status = SUCCEEDED
      assert @unit.complete?
      @unit.status = FAILED
      assert @unit.complete?
    end
    
    should "have JSON that includes job attributes" do
      job = Job.make
      unit_data = JSON.parse(job.work_units.first.to_json)
      assert unit_data['job_id'] == job.id
      assert unit_data['action'] == job.action
      assert JSON.parse(job.inputs).include? unit_data['input']
    end
    
    should "be able to retry, on failure" do
      @unit.update_attribute :worker_pid, 7337
      assert @unit.attempts == 0
      @unit.fail('oops', 10)
      assert @unit.worker_pid == nil
      assert @unit.attempts == 1
      assert @unit.processing?
      @unit.fail('oops again', 10)
      assert @unit.attempts == 2
      assert @unit.processing?
      assert @unit.job.processing?
      @unit.fail('oops one last time', 10)
      assert @unit.attempts == 3
      assert @unit.failed?
      assert @unit.job.any_work_units_failed?
    end
    
  end
  
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
cloud-crowd-0.6.2 test/unit/test_work_unit.rb
cloud-crowd-0.6.1 test/unit/test_work_unit.rb
cloud-crowd-0.6.0 test/unit/test_work_unit.rb
cloud-crowd-0.5.2 test/unit/test_work_unit.rb
cloud-crowd-0.5.0 test/unit/test_work_unit.rb
cloud-crowd-0.4.1 test/unit/test_work_unit.rb
cloud-crowd-0.4.0 test/unit/test_work_unit.rb
mooktakim-cloud-crowd-0.3.5 test/unit/test_work_unit.rb
mooktakim-cloud-crowd-0.3.4 test/unit/test_work_unit.rb
cloud-crowd-0.3.3 test/unit/test_work_unit.rb
cloud-crowd-0.3.2 test/unit/test_work_unit.rb
cloud-crowd-0.3.1 test/unit/test_work_unit.rb
cloud-crowd-0.3.0 test/unit/test_work_unit.rb
cloud-crowd-0.2.9 test/unit/test_work_unit.rb
cloud-crowd-0.2.8 test/unit/test_work_unit.rb
cloud-crowd-0.2.7 test/unit/test_work_unit.rb