Sha256: f197fe36df82ad73260df32f8db22716da60424018ce0a918d90b9af041a6307

Contents?: true

Size: 1.94 KB

Versions: 18

Compression:

Stored size: 1.94 KB

Contents

#!/usr/bin/env rspec
require 'spec_helper'

require 'puppet/util/retryaction'

describe Puppet::Util::RetryAction do
  let (:exceptions) {{ Puppet::Error => 'Puppet Error Exception' }}

  it 'should retry on any exception if no acceptable exceptions given' do
    Puppet::Util::RetryAction.expects(:sleep).with( (((2 ** 1) -1) * 0.1) )
    Puppet::Util::RetryAction.expects(:sleep).with( (((2 ** 2) -1) * 0.1) )

    expect do
      Puppet::Util::RetryAction.retry_action( :retries => 2 ) do
        raise ArgumentError, 'Fake Failure'
      end
    end.to raise_exception(Puppet::Util::RetryAction::RetryException::RetriesExceeded)
  end

  it 'should retry on acceptable exceptions' do
    Puppet::Util::RetryAction.expects(:sleep).with( (((2 ** 1) -1) * 0.1) )
    Puppet::Util::RetryAction.expects(:sleep).with( (((2 ** 2) -1) * 0.1) )

    expect do
      Puppet::Util::RetryAction.retry_action( :retries => 2, :retry_exceptions => exceptions) do
        raise Puppet::Error, 'Fake Failure'
      end
    end.to raise_exception(Puppet::Util::RetryAction::RetryException::RetriesExceeded)
  end

  it 'should not retry on unacceptable exceptions' do
    Puppet::Util::RetryAction.expects(:sleep).never

    expect do
      Puppet::Util::RetryAction.retry_action( :retries => 2, :retry_exceptions => exceptions) do
        raise ArgumentError
      end
    end.to raise_exception(ArgumentError)
  end

  it 'should succeed if nothing is raised' do
    Puppet::Util::RetryAction.expects(:sleep).never

    Puppet::Util::RetryAction.retry_action( :retries => 2) do
      true
    end
  end

  it 'should succeed if an expected exception is raised retried and succeeds' do
    should_retry = nil
    Puppet::Util::RetryAction.expects(:sleep).once

    Puppet::Util::RetryAction.retry_action( :retries => 2, :retry_exceptions => exceptions) do
      if should_retry
        true
      else
        should_retry = true
        raise Puppet::Error, 'Fake error'
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
puppet-2.7.26 spec/unit/util/retryaction_spec.rb
puppet-2.7.25 spec/unit/util/retryaction_spec.rb
puppet-2.7.24 spec/unit/util/retryaction_spec.rb
puppet-2.7.23 spec/unit/util/retryaction_spec.rb
puppet-2.7.22 spec/unit/util/retryaction_spec.rb
puppet-2.7.21 spec/unit/util/retryaction_spec.rb
puppet-2.7.20 spec/unit/util/retryaction_spec.rb
puppet-2.7.20.rc1 spec/unit/util/retryaction_spec.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/puppet-2.7.18/spec/unit/util/retryaction_spec.rb
puppet-2.7.19 spec/unit/util/retryaction_spec.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/puppet-2.7.18/spec/unit/util/retryaction_spec.rb
puppet-2.7.18 spec/unit/util/retryaction_spec.rb
puppet-2.7.17 spec/unit/util/retryaction_spec.rb
puppet-2.7.16 spec/unit/util/retryaction_spec.rb
puppet-2.7.14 spec/unit/util/retryaction_spec.rb
puppet-2.7.13 spec/unit/util/retryaction_spec.rb
puppet-2.7.12 spec/unit/util/retryaction_spec.rb
puppet-2.7.11 spec/unit/util/retryaction_spec.rb