Sha256: ed4e9c35f94569df910ea667abe762610ae789fea64413d33332e3bfde167b16

Contents?: true

Size: 1.66 KB

Versions: 15

Compression:

Stored size: 1.66 KB

Contents

require 'spec_helper'

describe PerfectQueue::Multiprocess::ThreadProcessor do
  describe '.new' do
    it 'returns a Multiprocess::ThreadProcessor' do
      runner = double('runner')
      processor_id = double('processor_id')
      config = {}
      processor = Multiprocess::ThreadProcessor.new(runner, processor_id, config)
      expect(processor).to be_an_instance_of(Multiprocess::ThreadProcessor)
      expect(processor.instance_variable_get(:@processor_id)).to eq(processor_id)
    end
  end

  describe '#force_stop' do
    let (:processor) do
      config = {logger: double('logger').as_null_object}
      Multiprocess::ThreadProcessor.new(double('runner'), double('processor_id'), config)
    end
    it 'force_stop' do
      processor.force_stop
      expect(processor.instance_variable_get(:@finish_flag).set?).to be true
    end
  end

  describe '#run_loop' do
    let (:processor) do
      config = {logger: double('logger').as_null_object}
      Multiprocess::ThreadProcessor.new(double('runner'), double('processor_id'), config)
    end
    it 'rescues error' do
      pq = object_double('PerfectQueue').as_stubbed_const
      allow(pq).to receive(:open).and_raise(RuntimeError)
      processor.__send__(:run_loop)
    end
  end

  describe '#process' do
    let (:runner) do
      r = double('runner')
      allow(r).to receive(:new).and_raise(RuntimeError)
      r
    end
    let (:processor) do
      config = {logger: double('logger').as_null_object}
      Multiprocess::ThreadProcessor.new(runner, double('processor_id'), config)
    end
    it 'rescues error' do
      expect{processor.__send__(:process, double('task', key: 1))}.to raise_error(RuntimeError)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
perfectqueue-0.8.54 spec/multiprocess/thread_processor_spec.rb
perfectqueue-0.10.1 spec/multiprocess/thread_processor_spec.rb
perfectqueue-0.8.53 spec/multiprocess/thread_processor_spec.rb
perfectqueue-0.8.52 spec/multiprocess/thread_processor_spec.rb
perfectqueue-0.10.0 spec/multiprocess/thread_processor_spec.rb
perfectqueue-0.8.51 spec/multiprocess/thread_processor_spec.rb
perfectqueue-0.8.50 spec/multiprocess/thread_processor_spec.rb
perfectqueue-0.9.2 spec/multiprocess/thread_processor_spec.rb
perfectqueue-0.9.1 spec/multiprocess/thread_processor_spec.rb
perfectqueue-0.9.0 spec/multiprocess/thread_processor_spec.rb
perfectqueue-0.8.49 spec/multiprocess/thread_processor_spec.rb
perfectqueue-0.8.48 spec/multiprocess/thread_processor_spec.rb
perfectqueue-0.8.47 spec/multiprocess/thread_processor_spec.rb
perfectqueue-0.8.46 spec/multiprocess/thread_processor_spec.rb
perfectqueue-0.8.45 spec/multiprocess/thread_processor_spec.rb