Sha256: 3a6da987acb4d1d286f2f4aea07f4e5d1d7385bac78f79c2366a67f20bc0b6fd

Contents?: true

Size: 1.48 KB

Versions: 41

Compression:

Stored size: 1.48 KB

Contents

require 'unit_spec_helper'

describe Rpush::Daemon::DispatcherLoop do
  def run_dispatcher_loop
    dispatcher_loop.start
    dispatcher_loop.stop
  end

  let(:notification) { double }
  let(:batch) { double(notification_processed: nil) }
  let(:queue) { Queue.new }
  let(:dispatcher) { double(dispatch: nil, cleanup: nil) }
  let(:dispatcher_loop) { Rpush::Daemon::DispatcherLoop.new(queue, dispatcher) }
  let(:store) { double(Rpush::Daemon::Store::ActiveRecord, release_connection: nil) }

  before do
    allow(Rpush::Daemon).to receive_messages(store: store)
    queue.push([notification, batch])
  end

  it 'logs errors' do
    logger = double
    allow(Rpush).to receive_messages(logger: logger)
    error = StandardError.new
    allow(dispatcher).to receive(:dispatch).and_raise(error)
    expect(Rpush.logger).to receive(:error).with(error)
    run_dispatcher_loop
  end

  it 'reflects an exception' do
    allow(Rpush).to receive_messages(logger: double(error: nil))
    error = StandardError.new
    allow(dispatcher).to receive(:dispatch).and_raise(error)
    expect(dispatcher_loop).to receive(:reflect).with(:error, error)
    run_dispatcher_loop
  end

  describe 'stop' do
    before do
      queue.clear
    end

    it 'instructs the dispatcher to cleanup' do
      expect(dispatcher).to receive(:cleanup)
      run_dispatcher_loop
    end

    it 'releases the store connection' do
      expect(Rpush::Daemon.store).to receive(:release_connection)
      run_dispatcher_loop
    end
  end
end

Version data entries

41 entries across 41 versions & 2 rubygems

Version Path
rpush-9.1.0 spec/unit/daemon/dispatcher_loop_spec.rb
rpush-9.0.0 spec/unit/daemon/dispatcher_loop_spec.rb
rpush-8.0.0 spec/unit/daemon/dispatcher_loop_spec.rb
rpush-7.0.1 spec/unit/daemon/dispatcher_loop_spec.rb
rpush-7.0.0 spec/unit/daemon/dispatcher_loop_spec.rb
rpush-6.0.1 spec/unit/daemon/dispatcher_loop_spec.rb
rpush-6.0.0 spec/unit/daemon/dispatcher_loop_spec.rb
rpush-5.4.0 spec/unit/daemon/dispatcher_loop_spec.rb
rpush-5.3.0 spec/unit/daemon/dispatcher_loop_spec.rb
rpush-5.2.0 spec/unit/daemon/dispatcher_loop_spec.rb
rpush-5.1.0 spec/unit/daemon/dispatcher_loop_spec.rb
rpush-5.0.0 spec/unit/daemon/dispatcher_loop_spec.rb
rpush-4.2.0 spec/unit/daemon/dispatcher_loop_spec.rb
rpush-4.1.1 spec/unit/daemon/dispatcher_loop_spec.rb
rpush-4.1.0 spec/unit/daemon/dispatcher_loop_spec.rb
rpush-4.0.1 spec/unit/daemon/dispatcher_loop_spec.rb
rpush-4.0.0 spec/unit/daemon/dispatcher_loop_spec.rb
rpush-3.3.1 spec/unit/daemon/dispatcher_loop_spec.rb
rpush-3.3.0 spec/unit/daemon/dispatcher_loop_spec.rb
rpush_extended-3.2.6 spec/unit/daemon/dispatcher_loop_spec.rb