Sha256: d6d21b8c91c21cf010d36f9d2ac0dab8e914d608874e9b49cad3ce2da1cefd9c

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 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 = client.call :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

    values.uniq.size.should == values.size
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
savon-2.1.0 spec/integration/zipcode_example_spec.rb
savon-2.0.3 spec/integration/zipcode_example_spec.rb
savon-2.0.2 spec/integration/zipcode_example_spec.rb
savon-2.0.1 spec/integration/zipcode_example_spec.rb