mirror of https://github.com/ansible/ansible.git
api: time.clock compatible code (#70650)
time.clock is removed in Python 3.8. Add time.clock compatible code. Fixes: #70649 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>pull/70679/head
parent
4a735adc21
commit
055871cbb8
@ -0,0 +1,2 @@
|
|||||||
|
bugfixes:
|
||||||
|
- api - time.clock is removed in Python 3.8, add backward compatible code (https://github.com/ansible/ansible/issues/70649).
|
@ -0,0 +1,48 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright: (c) 2020, Abhijeet Kasurde <akasurde@redhat.com>
|
||||||
|
# Copyright: (c) 2020, Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
|
||||||
|
from ansible.module_utils.api import rate_limit, retry
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
class TestRateLimit:
|
||||||
|
|
||||||
|
def test_ratelimit(self):
|
||||||
|
@rate_limit(rate=1, rate_limit=1)
|
||||||
|
def login_database():
|
||||||
|
return "success"
|
||||||
|
r = login_database()
|
||||||
|
|
||||||
|
assert r == 'success'
|
||||||
|
|
||||||
|
|
||||||
|
class TestRetry:
|
||||||
|
|
||||||
|
def test_no_retry_required(self):
|
||||||
|
self.counter = 0
|
||||||
|
|
||||||
|
@retry(retries=4, retry_pause=2)
|
||||||
|
def login_database():
|
||||||
|
self.counter += 1
|
||||||
|
return 'success'
|
||||||
|
|
||||||
|
r = login_database()
|
||||||
|
|
||||||
|
assert r == 'success'
|
||||||
|
assert self.counter == 1
|
||||||
|
|
||||||
|
def test_catch_exception(self):
|
||||||
|
|
||||||
|
@retry(retries=1)
|
||||||
|
def login_database():
|
||||||
|
return 'success'
|
||||||
|
|
||||||
|
with pytest.raises(Exception):
|
||||||
|
login_database()
|
Loading…
Reference in New Issue