def test_limit_rate_bails_out_after_waiting_max_time(app): checker = CheckExternalLinksBuilder(app) checker.init() app.config.linkcheck_rate_limit_timeout = 90.0 checker.rate_limits = {"localhost": RateLimit(90.0, 0.0)} worker = HyperlinkAvailabilityCheckWorker(checker) next_check = worker.limit_rate(FakeResponse()) assert next_check is None
def test_limit_rate_user_max_delay(app): app.config.linkcheck_rate_limit_timeout = 0.0 checker = CheckExternalLinksBuilder(app) checker.init() checker.rate_limits = {} worker = HyperlinkAvailabilityCheckWorker(checker) next_check = worker.limit_rate(FakeResponse()) assert next_check is None
def test_limit_rate_doubles_previous_wait_time(app): checker = CheckExternalLinksBuilder(app) checker.init() checker.rate_limits = {"localhost": RateLimit(60.0, 0.0)} worker = HyperlinkAvailabilityCheckWorker(checker) with mock.patch('time.time', return_value=0.0): next_check = worker.limit_rate(FakeResponse()) assert next_check == 120.0
def test_limit_rate_default_sleep(app): checker = CheckExternalLinksBuilder(app) checker.init() checker.rate_limits = {} worker = HyperlinkAvailabilityCheckWorker(checker) with mock.patch('time.time', return_value=0.0): next_check = worker.limit_rate(FakeResponse()) assert next_check == 60.0
def test_limit_rate_clips_wait_time_to_max_time(app): checker = CheckExternalLinksBuilder(app) checker.init() app.config.linkcheck_rate_limit_timeout = 90.0 checker.rate_limits = {"localhost": RateLimit(60.0, 0.0)} worker = HyperlinkAvailabilityCheckWorker(checker) with mock.patch('time.time', return_value=0.0): next_check = worker.limit_rate(FakeResponse()) assert next_check == 90.0