Sha256: 7f2bd9aa40d169c82453bd667f5f778574310da0e105fc1fcc0c1abe8fbce420

Contents?: true

Size: 1.12 KB

Versions: 16

Compression:

Stored size: 1.12 KB

Contents

 require "spec_helper"

describe "ZIP code example" do

  it "supports threads making requests simultaneously" do
    client = Savon.client(
      # The WSDL document provided by the service.
      :wsdl => "http://www.thomas-bayer.com/axis2/services/BLZService?wsdl",

      # Lower timeouts so these specs don't take forever when the service is not available.
      :open_timeout => 10,
      :read_timeout => 10,

      # Disable logging for cleaner spec output.
      :log => false
    )

    mutex = Mutex.new

    request_data = [70070010, 24050110, 20050550]
    threads_waiting = request_data.size

    threads = request_data.map do |blz|
      thread = Thread.new do
        response = call_and_fail_gracefully client, :get_bank, :message => { :blz => blz }
        Thread.current[:value] = response.body[:get_bank_response][:details]
        mutex.synchronize { threads_waiting -= 1 }
      end

      thread.abort_on_exception = true
      thread
    end

    sleep(1) until threads_waiting == 0

    threads.each(&:kill)
    values = threads.map { |thr| thr[:value] }.compact

    expect(values.uniq.size).to eq(values.size)
  end

end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
savon-2.12.1 spec/integration/zipcode_example_spec.rb
savon-2.12.0 spec/integration/zipcode_example_spec.rb
savon-2.11.2 spec/integration/zipcode_example_spec.rb
savon-SU-2.11.1b spec/integration/zipcode_example_spec.rb
savon-SU-2.11.1 spec/integration/zipcode_example_spec.rb
savon-2.11.1 spec/integration/zipcode_example_spec.rb
savon-2.11.0 spec/integration/zipcode_example_spec.rb
savon-2.10.1 spec/integration/zipcode_example_spec.rb
savon-2.10.0 spec/integration/zipcode_example_spec.rb
savon-2.9.0 spec/integration/zipcode_example_spec.rb
savon-2.8.1 spec/integration/zipcode_example_spec.rb
savon-2.8.0 spec/integration/zipcode_example_spec.rb
savon-2.7.2 spec/integration/zipcode_example_spec.rb
savon-2.7.1 spec/integration/zipcode_example_spec.rb
savon-2.7.0 spec/integration/zipcode_example_spec.rb
savon-2.6.0 spec/integration/zipcode_example_spec.rb