Sha256: 993c1c14a217bf34da0bb55eacf0f6653cd03cf6ec91f164807bb08c0d4f95b2

Contents?: true

Size: 1.95 KB

Versions: 4

Compression:

Stored size: 1.95 KB

Contents

#! /usr/bin/env ruby -S 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

4 entries across 4 versions & 1 rubygems

Version Path
puppet-3.0.0.rc8 spec/unit/util/retryaction_spec.rb
puppet-3.0.0.rc7 spec/unit/util/retryaction_spec.rb
puppet-3.0.0.rc5 spec/unit/util/retryaction_spec.rb
puppet-3.0.0.rc4 spec/unit/util/retryaction_spec.rb