Sha256: e8952744ee87268f6fc91cb03f40797530293f8c4a366f2afd8d3efb1d10f0ab

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

require 'helper'

class TestClass
  def initialize
    @backoff_counter = 0
    @options = { backoff_limit: 5 }
  end

  def test_method
    raise Aws::RDS::Errors::ServiceError.new(nil, 'service error')
  end

  def reset_backoff
    @backoff_counter = 0
  end

  def backoff
    @backoff_counter += 1

    raise StandardError, 'gave up' if @options[:backoff_limit] > 0 && @options[:backoff_limit] < @backoff_counter
  end

  extend RdsRotateDbSnapshots::ActionWrappers

  with_backoff :test_method
end

describe RdsRotateDbSnapshots::ActionWrappers do
  subject { TestClass.new }

  describe "#with_backoff" do
    it "does not retry if the exception raised is Aws::RDS::Errors::ExpiredToken" do
      allow(subject).to receive(:test_method).and_raise(Aws::RDS::Errors::ExpiredToken.new(nil, 'token expired'))
      expect(subject).not_to receive(:reset_backoff)
      expect(subject).not_to receive(:backoff)
      expect { subject.test_method }.to raise_error(Aws::RDS::Errors::ExpiredToken)
    end

    it "retries if the exception raised is Aws::RDS::Errors::ServiceError" do
      expect(subject).to receive(:backoff).exactly(6).and_call_original

      expect { subject.test_method }.to raise_error(StandardError, 'gave up')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rds-rotate-db-snapshots-0.5.2 spec/lib/rds_rotate_db_snapshots/action_wrappers_spec.rb