Sha256: 271eaca1323593cb57a7197d3986c10805dbf4aa549283f2636e0000952aa865

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

require_relative "../spec_helper"
require "logstash/circuit_breaker"

class DummyErrorTest < StandardError; end

describe LogStash::CircuitBreaker do
  let(:error_threshold) { 1 }
  let(:options) do 
    {
      :exceptions => [DummyErrorTest],
      :error_threshold => error_threshold 
    }
  end

  subject { LogStash::CircuitBreaker.new("testing", options) }


  it "closed by default" do
    expect(subject.closed?).to eq(true)
  end

  context "when having too many errors" do
    let(:future_time) { Time.now + 3600 }
    before do
      subject.execute do
        raise DummyErrorTest
      end
    end

    it "raised an exception if we have too many errors" do
      expect {
        subject.execute do
          raise DummyErrorTest
        end
      }.to raise_error(LogStash::CircuitBreaker::OpenBreaker)
    end

    it "sets the breaker to open" do
      expect(subject.closed?).to eq(false)
    end

    it "resets the breaker after the time before retry" do
      expect(Time).to receive(:now).at_least(1).and_return(future_time)
      expect(subject.closed?).to eq(true)
    end

    it "doesnt run the command" do
      runned = false

      begin
        subject.execute do
          runned = true
        end
      rescue LogStash::CircuitBreaker::OpenBreaker
      end

      expect(runned).to eq(false)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
logstash-input-lumberjack-1.0.3 spec/logstash/circuit_breaker_spec.rb
logstash-input-lumberjack-1.0.2 spec/logstash/circuit_breaker_spec.rb