Sha256: f2fe3b829741959bda5eb746c3c763dbeacd4d62a74e194884da49cf98f5815e

Contents?: true

Size: 1.86 KB

Versions: 11

Compression:

Stored size: 1.86 KB

Contents

require 'helper'
require 'sidekiq/processor'

class TestProcessor < MiniTest::Unit::TestCase
  TestException = Class.new(StandardError)
  TEST_EXCEPTION = TestException.new("kerboom!")

  describe 'with mock setup' do
    before do
      $invokes = 0
      @boss = MiniTest::Mock.new
      @processor = ::Sidekiq::Processor.new(@boss)
      Celluloid.logger = nil
      Sidekiq.redis = REDIS
    end

    class MockWorker
      include Sidekiq::Worker
      def perform(args)
        raise TEST_EXCEPTION if args == 'boom'
        args.pop if args.is_a? Array
        $invokes += 1
      end
    end

    it 'processes as expected' do
      msg = Sidekiq.dump_json({ 'class' => MockWorker.to_s, 'args' => ['myarg'] })
      @boss.expect(:processor_done!, nil, [@processor])
      @processor.process(msg, 'default')
      @boss.verify
      assert_equal 1, $invokes
    end

    it 'passes exceptions to ExceptionHandler' do
      msg = Sidekiq.dump_json({ 'class' => MockWorker.to_s, 'args' => ['boom'] })
      begin
        @processor.process(msg, 'default')
        flunk "Expected #process to raise exception"
      rescue TestException
      end

      assert_equal 0, $invokes
    end

    it 're-raises exceptions after handling' do
      msg = Sidekiq.dump_json({ 'class' => MockWorker.to_s, 'args' => ['boom'] })
      re_raise = false

      begin
        @processor.process(msg, 'default')
      rescue TestException
        re_raise = true
      end

      assert re_raise, "does not re-raise exceptions after handling"
    end

    it 'does not modify original arguments' do
      msg = { 'class' => MockWorker.to_s, 'args' => [['myarg']] }
      msgstr = Sidekiq.dump_json(msg)
      processor = ::Sidekiq::Processor.new(@boss)
      @boss.expect(:processor_done!, nil, [processor])
      processor.process(msgstr, 'default')
      assert_equal [['myarg']], msg['args']
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
sidekiq-2.5.2 test/test_processor.rb
sidekiq-2.5.1 test/test_processor.rb
sidekiq-2.5.0 test/test_processor.rb
sidekiq-2.4.0 test/test_processor.rb
sidekiq-2.3.3 test/test_processor.rb
sidekiq-2.3.2 test/test_processor.rb
sidekiq-2.3.1 test/test_processor.rb
sidekiq-2.3.0 test/test_processor.rb
sidekiq-2.2.1 test/test_processor.rb
sidekiq-2.2.0 test/test_processor.rb
sidekiq-2.1.1 test/test_processor.rb