Sha256: 4d704bd421b22aa1363bf244163e03b000d3d2e8832bb0e539c6863cd56a61a7

Contents?: true

Size: 1.12 KB

Versions: 11

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

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

end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
savon-2.5.1 spec/integration/zipcode_example_spec.rb
savon-2.5.0 spec/integration/zipcode_example_spec.rb
savon_with_adapter-2.4.1 spec/integration/zipcode_example_spec.rb
savon-2.4.0 spec/integration/zipcode_example_spec.rb
savon-2.3.3 spec/integration/zipcode_example_spec.rb
savon-2.3.2 spec/integration/zipcode_example_spec.rb
savon-2.3.1 spec/integration/zipcode_example_spec.rb
savon-ng-1.6-2.4.1 spec/integration/zipcode_example_spec.rb
savon-ng-1.6-2.4.0 spec/integration/zipcode_example_spec.rb
savon-2.3.0 spec/integration/zipcode_example_spec.rb
savon-2.2.0 spec/integration/zipcode_example_spec.rb