Sha256: 46a1ba9ac9f1a008061f5f47e744f6f7a4c7335ef71bfa09a850e014cf389ed6

Contents?: true

Size: 1.49 KB

Versions: 7

Compression:

Stored size: 1.49 KB

Contents

require 'securerandom'

RSpec.describe WorkerKiller::Middleware do
  let(:logger){ Logger.new(nil) }

  let(:app){ double }
  let(:reaction){ ->{} }
  let(:anykey){ SecureRandom.hex(8) }

  describe 'Custom class' do
    let(:klass){ double }
    let(:options){ { klass: klass, reaction: reaction, anykey: anykey } }
    subject{ described_class.new(app, options) }

    it 'is expected to be initialized' do
      expect(klass).to receive(:new).with(anykey: anykey).and_return(99)
      expect(subject.limiter).to eq(99)
    end
  end

  describe WorkerKiller::Middleware::RequestsLimiter do
    let(:options){ { reaction: reaction, min: 1111 } }
    subject{ described_class.new(app, options) }

    it 'is expected to be initialized with reaction' do
      expect(WorkerKiller::CountLimiter).to receive(:new).with(min: 1111).and_call_original
      expect(subject.limiter).to be_an(WorkerKiller::CountLimiter)
      expect(subject.limiter.min).to eq(1111)
      expect(subject.limiter.reaction).to eq(reaction)
    end
  end

  describe WorkerKiller::Middleware::OOMLimiter do
    let(:options){ { reaction: reaction, min: 2222 } }
    subject{ described_class.new(app, options) }

    it 'is expected to be initialized with reaction' do
      expect(WorkerKiller::MemoryLimiter).to receive(:new).with(min: 2222).and_call_original
      expect(subject.limiter).to be_an(WorkerKiller::MemoryLimiter)
      expect(subject.limiter.min).to eq(2222)
      expect(subject.limiter.reaction).to eq(reaction)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
worker_killer-0.1.1.30345 spec/middleware_spec.rb
worker_killer-0.1.0.30337 spec/middleware_spec.rb
worker_killer-0.1.0.19844 spec/middleware_spec.rb
worker_killer-0.1.0.19842 spec/middleware_spec.rb
worker_killer-0.1.0.19841 spec/middleware_spec.rb
worker_killer-0.1.0.19840 spec/middleware_spec.rb
worker_killer-0.1.0.19839 spec/middleware_spec.rb