Sha256: 3aaeed64ca80137060379bb232b74cb492a39d0b4dd7530374ac637bd8fd0f5b

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

require 'spec_helper'

RSpec.describe Muxer::Multiplexer do
  let(:multiplexer) { Muxer::Multiplexer.new }

  it 'kills requests with a timeout' do
    VCR.use_cassette('muxer/multiplexer/with_a_timeout') do
      multiplexer.add_url('https://github.com//', 0.0001)
      response = multiplexer.execute

      expect(response[:succeeded].count).to eq(0)
      expect(response[:failed].count).to eq(1)
   end
  end

  it 'lets a request wait on the longer one' do
    VCR.use_cassette('muxer/multiplexer/with_one_timeout') do
      multiplexer.add_url('https://github.com/', 0.0001)
      multiplexer.add_url('https://codeclimate.com/', 2)
      response = multiplexer.execute

      expect(response[:succeeded].count).to eq(2)
      expect(response[:failed].count).to eq(0)
    end
  end

  it 'kills requests with a global timeout' do
    VCR.use_cassette('muxer/multiplexer/with_a_global_timeout') do
      multiplexer.add_url('https://github.com/')
      multiplexer.timeout = 0.0001
      response = multiplexer.execute

      expect(response[:succeeded].count).to eq(0)
      expect(response[:failed].count).to eq(1)
    end
  end

  it 'kills one of two requests with a global timeout' do
    VCR.use_cassette('muxer/multiplexer/with_global_timeout') do
      multiplexer.add_url('https://github.com/')
      multiplexer.add_url('https://www.google.com/')
      multiplexer.timeout = 0.2
      response = multiplexer.execute

      expect(response[:succeeded].count).to eq(1)
      expect(response[:failed].count).to eq(1)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
muxer-0.1.3 spec/muxer/multiplexer_spec.rb
muxer-0.1.2 spec/muxer/multiplexer_spec.rb