Sha256: 789dc4c4188efbf48997b32162d54e7f1c1d47b532319740be798d36283e9c0f

Contents?: true

Size: 1.45 KB

Versions: 25

Compression:

Stored size: 1.45 KB

Contents

require 'test_helper'

class WorkerTest < Test::Unit::TestCase
  
  context "A CloudCrowd::Worker" do
        
    setup do
      @node = Node.new.instance_variable_get(:@app)
      @unit = WorkUnit.make
      @worker = Worker.new(@node, JSON.parse(@unit.to_json))
    end
    
    should "instantiate correctly" do
      assert @worker.pid == $$
      assert @worker.unit['id'] == @unit.id
      assert @worker.status == @unit.status
      assert @worker.node == @node
      assert @worker.time_taken > 0
    end
    
    should "be able to retry operations that must succeed" do
      @worker.instance_variable_set :@retry_wait, 0.01
      @worker.expects(:log).at_least(3)
      tries = 0
      @worker.keep_trying_to("do something critical") do
        tries += 1;
        raise 'hell' unless tries > 3
        assert "made it through"
      end    
    end
    
    should "be able to run an action and try to complete it" do
      GraphicsMagick.any_instance.expects(:process).returns('the answer')
      GraphicsMagick.any_instance.expects(:cleanup_work_directory)
      @worker.expects(:complete_work_unit).with({'output' => 'the answer'}.to_json)
      @worker.run_work_unit
    end
    
    should "enchance the options that an action receives with extra info" do
      opts = @worker.enhanced_unit_options
      assert opts['work_unit_id'] == @unit.id
      assert opts['job_id'] == @unit.job.id
      assert opts['attempts'] == @unit.attempts
    end
      
  end
  
end

Version data entries

25 entries across 25 versions & 3 rubygems

Version Path
documentcloud-cloud-crowd-0.2.1 test/unit/test_worker.rb
documentcloud-cloud-crowd-0.2.2 test/unit/test_worker.rb
documentcloud-cloud-crowd-0.2.3 test/unit/test_worker.rb
cloud-crowd-0.6.2 test/unit/test_worker.rb
cloud-crowd-0.6.1 test/unit/test_worker.rb
cloud-crowd-0.6.0 test/unit/test_worker.rb
cloud-crowd-0.5.2 test/unit/test_worker.rb
cloud-crowd-0.5.0 test/unit/test_worker.rb
cloud-crowd-0.4.1 test/unit/test_worker.rb
cloud-crowd-0.4.0 test/unit/test_worker.rb
mooktakim-cloud-crowd-0.3.5 test/unit/test_worker.rb
mooktakim-cloud-crowd-0.3.4 test/unit/test_worker.rb
cloud-crowd-0.3.3 test/unit/test_worker.rb
cloud-crowd-0.3.2 test/unit/test_worker.rb
cloud-crowd-0.3.1 test/unit/test_worker.rb
cloud-crowd-0.3.0 test/unit/test_worker.rb
cloud-crowd-0.2.9 test/unit/test_worker.rb
cloud-crowd-0.2.8 test/unit/test_worker.rb
cloud-crowd-0.2.7 test/unit/test_worker.rb
cloud-crowd-0.2.6 test/unit/test_worker.rb