Sha256: 5e01bfb49de9f06a36dd20539200b280a2b8632cfe872c7de1626d4caa8aac1e

Contents?: true

Size: 1.61 KB

Versions: 30

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe LHC::Request do
  let(:request_options) do
    [
      { url: 'http://www.local.ch/restaurants' },
      { url: 'http://www.local.ch' }
    ]
  end

  let(:stub_parallel_requests) do
    stub_request(:get, "http://www.local.ch/restaurants").to_return(status: 200, body: '1')
    stub_request(:get, "http://www.local.ch").to_return(status: 200, body: '2')
  end

  it 'does parallel requests if you provide an array of requests' do
    stub_parallel_requests
    responses = LHC.request(request_options)
    expect(responses[0].body).to eq '1'
    expect(responses[1].body).to eq '2'
  end

  context 'interceptors' do
    before(:each) do
      class TestInterceptor < LHC::Interceptor; end
      LHC.configure { |c| c.interceptors = [TestInterceptor] }
    end

    it 'calls interceptors also for parallel requests' do
      stub_parallel_requests
      @called = 0
      allow_any_instance_of(TestInterceptor)
        .to receive(:before_request) { @called += 1 }
      LHC.request(request_options)
      expect(@called).to eq 2
    end
  end

  context 'webmock disabled' do
    before do
      WebMock.disable!
    end

    after do
      WebMock.enable!
    end

    it 'does not memorize parallelization handlers in typhoeus (hydra) in case one request of the parallization fails' do
      begin
        LHC.request([{ url: 'https://www.google.com/' }, { url: 'https://nonexisting123' }, { url: 'https://www.google.com/' }, { url: 'https://nonexisting123' }])
      rescue LHC::UnknownError
      end

      LHC.request([{ url: 'https://www.google.com' }])
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
lhc-15.2.1 spec/request/parallel_requests_spec.rb
lhc-15.2.0 spec/request/parallel_requests_spec.rb
lhc-15.1.3 spec/request/parallel_requests_spec.rb
lhc-15.1.2 spec/request/parallel_requests_spec.rb
lhc-15.1.1 spec/request/parallel_requests_spec.rb
lhc-15.1.0 spec/request/parallel_requests_spec.rb
lhc-16.0.0.pre.pro2162.2 spec/request/parallel_requests_spec.rb
lhc-16.0.0.pre.pro2162 spec/request/parallel_requests_spec.rb
lhc-15.0.1 spec/request/parallel_requests_spec.rb
lhc-15.0.0 spec/request/parallel_requests_spec.rb
lhc-14.0.0 spec/request/parallel_requests_spec.rb
lhc-13.4.0.pre.pro1766.1 spec/request/parallel_requests_spec.rb
lhc-13.2.0 spec/request/parallel_requests_spec.rb
lhc-13.1.0 spec/request/parallel_requests_spec.rb
lhc-13.0.0 spec/request/parallel_requests_spec.rb
lhc-12.3.0 spec/request/parallel_requests_spec.rb
lhc-12.2.1 spec/request/parallel_requests_spec.rb
lhc-12.2.0 spec/request/parallel_requests_spec.rb
lhc-12.1.3 spec/request/parallel_requests_spec.rb
lhc-12.1.2 spec/request/parallel_requests_spec.rb