Sha256: ba892c3e444c85700c824bc9704358603c19822c2ca25e8cb0f257b499c51ed4

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

require 'spec_helper'

describe Hawkei::Processor::Batch do
  let(:batch) { Hawkei::Processor::Batch.new }

  context 'set defaults' do
    it { expect(batch.messages).to eq([]) }
    it { expect(batch.can_retry?).to be_truthy }
    it { expect(batch.full?).to be_falsey }
    it { expect(batch.empty?).to be_truthy }
  end

  context 'add message' do
    before { batch << { test: 'hello' }}

    it { expect(batch.messages).to eq([{ test: 'hello' }]) }
    it { expect(batch.full?).to be_falsey }
    it { expect(batch.empty?).to be_falsey }
  end

  context 'with extended task' do
    before { batch.update_retry }

    it { expect(batch.can_retry?).to be_truthy }
    it { expect(batch.next_retry).to eq(2) }
  end

  context 'with extended task' do
    before do
      11.times { batch.update_retry }
    end

    it { expect(batch.can_retry?).to be_falsey }
    it { expect(batch.next_retry).to eq(60) }
  end

  context 'with max number of messages reached' do
    before { 100.times { batch << { test: 'hello' }}}

    it { expect(batch.full?).to be_truthy }
    it { expect(batch.empty?).to be_falsey }
  end

  context 'with max size reached' do
    before { 20.times { batch << 1000.times.map {{ test: 'hello' }}}}

    it { expect(batch.full?).to be_truthy }
    it { expect(batch.empty?).to be_falsey }
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hawkei-1.1.0 spec/lib/hawkei/processor/batch_spec.rb
hawkei-1.0.0 spec/lib/hawkei/processor/batch_spec.rb