Increase unit tests coverage

Change-Id: Icb0a98000dfe830686915c6c6a27f1b4310d91e6
This commit is contained in:
Federico Ceratto 2015-07-20 21:51:12 +01:00
parent 1175e59d46
commit 9fc9d55184
3 changed files with 1770 additions and 8 deletions

View File

@ -72,7 +72,7 @@ def retry(cb=None, retries=50, delay=150):
"""A retry decorator that ignores attempts at creating nested retries""" """A retry decorator that ignores attempts at creating nested retries"""
def outer(f): def outer(f):
@functools.wraps(f) @functools.wraps(f)
def wrapper(self, *args, **kwargs): def retry_wrapper(self, *args, **kwargs):
if not hasattr(RETRY_STATE, 'held'): if not hasattr(RETRY_STATE, 'held'):
# Create the state vars if necessary # Create the state vars if necessary
RETRY_STATE.held = False RETRY_STATE.held = False
@ -109,7 +109,9 @@ def retry(cb=None, retries=50, delay=150):
result = f(self, *copy.deepcopy(args), **copy.deepcopy(kwargs)) result = f(self, *copy.deepcopy(args), **copy.deepcopy(kwargs))
return result return result
return wrapper retry_wrapper.__wrapped_function = f
retry_wrapper.__wrapper_name = 'retry'
return retry_wrapper
return outer return outer
@ -117,7 +119,7 @@ def retry(cb=None, retries=50, delay=150):
def transaction(f): def transaction(f):
@retry(cb=_retry_on_deadlock) @retry(cb=_retry_on_deadlock)
@functools.wraps(f) @functools.wraps(f)
def wrapper(self, *args, **kwargs): def transaction_wrapper(self, *args, **kwargs):
self.storage.begin() self.storage.begin()
try: try:
result = f(self, *args, **kwargs) result = f(self, *args, **kwargs)
@ -127,7 +129,9 @@ def transaction(f):
with excutils.save_and_reraise_exception(): with excutils.save_and_reraise_exception():
self.storage.rollback() self.storage.rollback()
return wrapper transaction_wrapper.__wrapped_function = f
transaction_wrapper.__wrapper_name = 'transaction'
return transaction_wrapper
def synchronized_domain(domain_arg=1, new_domain=False): def synchronized_domain(domain_arg=1, new_domain=False):
@ -138,7 +142,7 @@ def synchronized_domain(domain_arg=1, new_domain=False):
""" """
def outer(f): def outer(f):
@functools.wraps(f) @functools.wraps(f)
def wrapper(self, *args, **kwargs): def sync_wrapper(self, *args, **kwargs):
if not hasattr(DOMAIN_LOCKS, 'held'): if not hasattr(DOMAIN_LOCKS, 'held'):
# Create the held set if necessary # Create the held set if necessary
DOMAIN_LOCKS.held = set() DOMAIN_LOCKS.held = set()
@ -201,14 +205,17 @@ def synchronized_domain(domain_arg=1, new_domain=False):
DOMAIN_LOCKS.held.remove(domain_id) DOMAIN_LOCKS.held.remove(domain_id)
return result return result
return wrapper sync_wrapper.__wrapped_function = f
sync_wrapper.__wrapper_name = 'synchronized_domain'
return sync_wrapper
return outer return outer
def notification(notification_type): def notification(notification_type):
def outer(f): def outer(f):
@functools.wraps(f) @functools.wraps(f)
def wrapper(self, *args, **kwargs): def notification_wrapper(self, *args, **kwargs):
if not hasattr(NOTIFICATION_BUFFER, 'queue'): if not hasattr(NOTIFICATION_BUFFER, 'queue'):
# Create the notifications queue if necessary # Create the notifications queue if necessary
NOTIFICATION_BUFFER.stack = 0 NOTIFICATION_BUFFER.stack = 0
@ -247,7 +254,7 @@ def notification(notification_type):
# Reset the queue # Reset the queue
NOTIFICATION_BUFFER.queue.clear() NOTIFICATION_BUFFER.queue.clear()
return wrapper return notification_wrapper
return outer return outer

File diff suppressed because it is too large Load Diff