Sha256: 26efbe8bb52dc40ea23c75a70c4dd6f2e2415a7370575912fcc3eef95c8582d2

Contents?: true

Size: 1.3 KB

Versions: 3

Compression:

Stored size: 1.3 KB

Contents

require 'spec_helper'

describe LiveQA::Processor::Batch do
  let(:batch) { LiveQA::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

3 entries across 3 versions & 1 rubygems

Version Path
liveqa-1.9.6 spec/lib/liveqa/processor/batch_spec.rb
liveqa-1.9.5 spec/lib/liveqa/processor/batch_spec.rb
liveqa-1.9.4 spec/lib/liveqa/processor/batch_spec.rb