require 'test_helper' module GovDelivery::Proctor require 'logger' end class TestProctor < Test::Unit::TestCase def test_sleep_time_steady assert_equal 30, GovDelivery::Proctor.sleep_time('steady', 600, 30, 5) end def test_sleep_time_backoff_iteration_one assert_equal 60, GovDelivery::Proctor.sleep_time('backoff', 600, 30, 1) end def test_sleep_time_backoff_iteration_four assert_equal 480, GovDelivery::Proctor.sleep_time('backoff', 600, 30, 4) end def test_sleep_time_accelerate_iteration_default_to_minimum assert_equal 10, GovDelivery::Proctor.sleep_time('accelerate', 1, 10, 2) end def test_sleep_time_accelerate_iteration_one assert_equal 90, GovDelivery::Proctor.sleep_time('accelerate', 600, 10, 1) end def test_sleep_time_accelerate_iteration_four assert_equal 40, GovDelivery::Proctor.sleep_time('accelerate', 600, 10, 4) end def test_sleep_time_accelerate_iteration_four_lower_sleep assert_equal 4, GovDelivery::Proctor.sleep_time('accelerate', 600, 1, 4) end def test_backoff_check_condition_true GovDelivery::Proctor.backoff_check 2 do true end end def test_accelerating_check_condition_true GovDelivery::Proctor.accelerating_check 2 do true end end def test_steady_check_condition_true GovDelivery::Proctor.steady_check 2 do true end end def test_backoff_check_condition_false ex = assert_raises GovDelivery::Proctor::CheckTimeExceeded do GovDelivery::Proctor.backoff_check 1 do false end end assert_equal "Backoff check has taken too long. Have waited 1 seconds\nlog: ", ex.message end def test_accelerating_check_condition_false ex = assert_raises GovDelivery::Proctor::CheckTimeExceeded do GovDelivery::Proctor.accelerating_check 1 do false end end assert_equal "Backon check has taken too long. Have waited 1 seconds\nlog: ", ex.message end def test_steady_check_condition_false ex = assert_raises GovDelivery::Proctor::CheckTimeExceeded do GovDelivery::Proctor.steady_check 1 do false end end assert_equal "Steady check has taken too long. Have waited 1 seconds\nlog: ", ex.message end def test_backoff_check_requires_block ex = assert_raises RuntimeError do GovDelivery::Proctor.backoff_check 1 end assert_equal 'Check requires a block', ex.message end def test_accelerating_check_requires_block ex = assert_raises RuntimeError do GovDelivery::Proctor.accelerating_check 1 end assert_equal 'Check requires a block', ex.message end def test_steady_check_requires_block ex = assert_raises RuntimeError do GovDelivery::Proctor.steady_check 1 end assert_equal 'Check requires a block', ex.message end end