Sha256: 94ead2ab03d5229006868249ab7a03fbeab3cccf76cc1c463a8b5f246d9b7d00

Contents?: true

Size: 1.27 KB

Versions: 23

Compression:

Stored size: 1.27 KB

Contents

require 'test_plugin_helper'
require 'foreman_tasks/test_helpers'

class ExponentialBackoffTest < ActiveSupport::TestCase
  include ForemanTasks::TestHelpers::WithInThreadExecutor

  class TestAction < ::Actions::EntryAction
    include ::ForemanRhCloud::Async::ExponentialBackoff

    def try_execute
      action_callback&.call(self)
    end

    # define a method to execute code inside the class context.
    def action_callback(instance)
    end
  end

  test 'executes an action once' do
    TestAction.any_instance.expects(:action_callback).returns(->(instance) { instance.done! })

    ForemanTasks.sync_task(TestAction)
  end

  test 'fails after a single excution if done was called' do
    TestAction.any_instance.expects(:action_callback).returns(
      lambda do |instance|
        instance.done!
        raise ::Foreman::Exception('Foo')
      end)

    ForemanTasks.sync_task(TestAction)
  end

  test 'executes the task three times before failing it' do
    # speed up the execution
    TestAction.any_instance.stubs(:poll_intervals).returns([0, 0, 0])

    TestAction.any_instance.expects(:action_callback).raises(::Foreman::Exception.new('Foo')).times(3)

    ForemanTasks.sync_task(TestAction)
  rescue ForemanTasks::TaskError => ex
    assert ex.aggregated_message =~ /Foo/
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
foreman_rh_cloud-9.0.59 test/jobs/exponential_backoff_test.rb
foreman_rh_cloud-9.0.58 test/jobs/exponential_backoff_test.rb
foreman_rh_cloud-9.0.57 test/jobs/exponential_backoff_test.rb
foreman_rh_cloud-10.0.1 test/jobs/exponential_backoff_test.rb
foreman_rh_cloud-9.0.56 test/jobs/exponential_backoff_test.rb
foreman_rh_cloud-9.0.55 test/jobs/exponential_backoff_test.rb
foreman_rh_cloud-9.0.54 test/jobs/exponential_backoff_test.rb
foreman_rh_cloud-9.0.53 test/jobs/exponential_backoff_test.rb
foreman_rh_cloud-9.0.52 test/jobs/exponential_backoff_test.rb
foreman_rh_cloud-8.0.52 test/jobs/exponential_backoff_test.rb
foreman_rh_cloud-9.0.51 test/jobs/exponential_backoff_test.rb
foreman_rh_cloud-8.0.51 test/jobs/exponential_backoff_test.rb
foreman_rh_cloud-7.0.48 test/jobs/exponential_backoff_test.rb
foreman_rh_cloud-7.0.47 test/jobs/exponential_backoff_test.rb
foreman_rh_cloud-8.0.50 test/jobs/exponential_backoff_test.rb
foreman_rh_cloud-8.0.49 test/jobs/exponential_backoff_test.rb
foreman_rh_cloud-8.0.48 test/jobs/exponential_backoff_test.rb
foreman_rh_cloud-8.0.47 test/jobs/exponential_backoff_test.rb
foreman_rh_cloud-8.0.46 test/jobs/exponential_backoff_test.rb
foreman_rh_cloud-6.0.45 test/jobs/exponential_backoff_test.rb