Sha256: 77c17fe9424e195c5f8759da61bf4b9eb9a195476e5f7dba1f2ce8085567551f

Contents?: true

Size: 1.34 KB

Versions: 36

Compression:

Stored size: 1.34 KB

Contents

require 'core/spec_helper'

describe ZendeskAPI::Middleware::Request::Retry do
  def runtime
    start = Time.now.to_f
    yield
    Time.now.to_f - start
  end

  [429, 503].each do |error_code|
    it "should wait requisite seconds and then retry request on #{error_code}" do
      stub_request(:get, %r{blergh}).
        to_return(:status => 429, :headers => { :retry_after => 1 }).
        to_return(:status => 200)

      seconds = runtime {
        expect(client.connection.get("blergh").status).to eq(200)
      }

      expect(seconds).to be_within(0.2).of(1)
    end
  end

  context "with failing request", :prevent_logger_changes do
    before do
      stub_request(:get, %r{blergh}).
        to_return(:status => 503).
        to_return(:status => 200)

      expect_any_instance_of(ZendeskAPI::Middleware::Request::Retry).to receive(:sleep).exactly(10).times.with(1)
    end

    it "should wait default timeout seconds and then retry request on error" do
      expect(runtime {
        expect(client.connection.get("blergh").status).to eq(200)
      }).to be <= 0.5
    end

    it "should print to logger" do
      expect(client.config.logger).to receive(:warn).at_least(:once)
      client.connection.get("blergh")
    end

    it "should not fail without a logger" do
      client.config.logger = false
      client.connection.get("blergh")
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
zendesk_api-1.13.1 spec/core/middleware/request/retry_spec.rb
zendesk_api-1.12.1 spec/core/middleware/request/retry_spec.rb
zendesk_api-1.12.0 spec/core/middleware/request/retry_spec.rb
zendesk_api-1.11.7 spec/core/middleware/request/retry_spec.rb
zendesk_api-1.11.6 spec/core/middleware/request/retry_spec.rb
zendesk_api-1.11.5 spec/core/middleware/request/retry_spec.rb
zendesk_api-1.11.4 spec/core/middleware/request/retry_spec.rb
zendesk_api-1.11.3 spec/core/middleware/request/retry_spec.rb
zendesk_api-1.11.2 spec/core/middleware/request/retry_spec.rb
zendesk_api-1.11.1 spec/core/middleware/request/retry_spec.rb
zendesk_api-1.11.0 spec/core/middleware/request/retry_spec.rb
zendesk_api-1.10.0 spec/core/middleware/request/retry_spec.rb
zendesk_api-1.9.6 spec/core/middleware/request/retry_spec.rb
zendesk_api-1.9.5 spec/core/middleware/request/retry_spec.rb
zendesk_api-1.9.4 spec/core/middleware/request/retry_spec.rb
zendesk_api-1.9.3 spec/core/middleware/request/retry_spec.rb
zendesk_api-1.9.2 spec/core/middleware/request/retry_spec.rb
zendesk_api-1.9.1 spec/core/middleware/request/retry_spec.rb
zendesk_api-1.9.0 spec/core/middleware/request/retry_spec.rb
zendesk_api-1.8.0 spec/core/middleware/request/retry_spec.rb