Sha256: 6a646463d816db9961c0ed0fad2898f166679d7d6a6be4da1fb83323a700b66c

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

require 'test_helper'

class WorkUnitTest < Test::Unit::TestCase

  context "A WorkUnit" do
    
    setup do
      @unit = WorkUnit.make
      @job = @unit.job
    end
    
    subject { @unit }
    
    should_belong_to :job
    
    should_validate_presence_of :job_id, :status, :input
    
    should "know if its done" do
      assert !@unit.complete?
      @unit.status = CloudCrowd::SUCCEEDED
      assert @unit.complete?
      @unit.status = CloudCrowd::FAILED
      assert @unit.complete?
      @unit.expects :check_for_job_completion
      @unit.save
    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 :taken, true
      assert @unit.attempts == 0
      @unit.fail('oops', 10)
      assert @unit.taken == false
      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

2 entries across 2 versions & 1 rubygems

Version Path
documentcloud-cloud-crowd-0.0.1 test/unit/test_work_unit.rb
documentcloud-cloud-crowd-0.0.2 test/unit/test_work_unit.rb