Sha256: 661a7e181e739696a86c6a73bd9aed63277bd7b7b5e36ed3c97ba6b324ed2589

Contents?: true

Size: 1.13 KB

Versions: 62

Compression:

Stored size: 1.13 KB

Contents

# The time a 3rd-party shipping provider takes to respond to a request varies greatly.
# This class simulates these unpredictable delays in shipping rate retrieval so that
# load-testing tools run into situations that more accurately reflect the real world.

module ActiveShipping
  class BenchmarkCarrier < Carrier
    cattr_reader :name
    @@name = "Benchmark Carrier"

    def find_rates(origin, destination, packages, options = {})
      origin = Location.from(origin)
      destination = Location.from(destination)
      packages = Array(packages)

      delay_time = generate_simulated_lag

      bogus_estimate = RateEstimate.new(
        origin, destination, @@name,
        "Free Benchmark Shipping", total_price: 0, currency: 'USD',
                                   packages: packages, delivery_range: [Time.now.utc.strftime("%Y-%d-%m"), Time.now.utc.strftime("%Y-%d-%m")]
        )
      RateResponse.new(true, "Success (delayed #{delay_time} seconds)", { rate: 'free' }, rates: [bogus_estimate], xml: "<rate>free</rate>")
    end

    private

    def generate_simulated_lag(max_delay = 30)
      sleep Random.rand * max_delay
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 vendor/active_shipping/lib/active_shipping/carriers/benchmark_carrier.rb
workarea-core-3.5.26 vendor/active_shipping/lib/active_shipping/carriers/benchmark_carrier.rb
workarea-core-3.4.45 vendor/active_shipping/lib/active_shipping/carriers/benchmark_carrier.rb
workarea-core-3.5.25 vendor/active_shipping/lib/active_shipping/carriers/benchmark_carrier.rb
workarea-core-3.5.23 vendor/active_shipping/lib/active_shipping/carriers/benchmark_carrier.rb
workarea-core-3.4.44 vendor/active_shipping/lib/active_shipping/carriers/benchmark_carrier.rb
workarea-core-3.5.22 vendor/active_shipping/lib/active_shipping/carriers/benchmark_carrier.rb
workarea-core-3.4.43 vendor/active_shipping/lib/active_shipping/carriers/benchmark_carrier.rb
workarea-core-3.5.21 vendor/active_shipping/lib/active_shipping/carriers/benchmark_carrier.rb
workarea-core-3.4.42 vendor/active_shipping/lib/active_shipping/carriers/benchmark_carrier.rb
workarea-core-3.5.20 vendor/active_shipping/lib/active_shipping/carriers/benchmark_carrier.rb
workarea-core-3.4.41 vendor/active_shipping/lib/active_shipping/carriers/benchmark_carrier.rb
workarea-core-3.5.19 vendor/active_shipping/lib/active_shipping/carriers/benchmark_carrier.rb
workarea-core-3.4.40 vendor/active_shipping/lib/active_shipping/carriers/benchmark_carrier.rb
workarea-core-3.5.18 vendor/active_shipping/lib/active_shipping/carriers/benchmark_carrier.rb
workarea-core-3.4.39 vendor/active_shipping/lib/active_shipping/carriers/benchmark_carrier.rb
workarea-core-3.5.17 vendor/active_shipping/lib/active_shipping/carriers/benchmark_carrier.rb
workarea-core-3.4.38 vendor/active_shipping/lib/active_shipping/carriers/benchmark_carrier.rb
workarea-core-3.5.16 vendor/active_shipping/lib/active_shipping/carriers/benchmark_carrier.rb
workarea-core-3.4.37 vendor/active_shipping/lib/active_shipping/carriers/benchmark_carrier.rb