Commit 8c975d5e authored by Thomas Thrainer's avatar Thomas Thrainer
Browse files

Add an expected block option to RunWithLocks



To compensate for the cases where a QA test is supposed to block when
a lock is present, add an additional option showing whether blocking is
supposed to happen or not.
Signed-off-by: default avatarHrvoje Ribicic <riba@google.com>
Reviewed-by: default avatarPetr Pudlak <pudlak@google.com>
Signed-off-by: default avatarThomas Thrainer <thomasth@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>

(cherry picked from commit 57efdaf5)

Conflicts:
	qa/qa_rapi.py (didn't backport changes to this file)
parent 1e00b69b
...@@ -192,7 +192,7 @@ def _GetBlockingLocks(): ...@@ -192,7 +192,7 @@ def _GetBlockingLocks():
# TODO: Can this be done as a decorator? Implement as needed. # TODO: Can this be done as a decorator? Implement as needed.
def RunWithLocks(fn, locks, timeout, *args, **kwargs): def RunWithLocks(fn, locks, timeout, block, *args, **kwargs):
""" Runs the given function, acquiring a set of locks beforehand. """ Runs the given function, acquiring a set of locks beforehand.
@type fn: function @type fn: function
...@@ -202,6 +202,8 @@ def RunWithLocks(fn, locks, timeout, *args, **kwargs): ...@@ -202,6 +202,8 @@ def RunWithLocks(fn, locks, timeout, *args, **kwargs):
@type timeout: number @type timeout: number
@param timeout: The number of seconds the locks should be held before @param timeout: The number of seconds the locks should be held before
expiring. expiring.
@type block: bool
@param block: Whether the test should block when locks are used or not.
This function allows a set of locks to be acquired in preparation for a QA This function allows a set of locks to be acquired in preparation for a QA
test, to try and see if the function can run in parallel with other test, to try and see if the function can run in parallel with other
...@@ -256,10 +258,13 @@ def RunWithLocks(fn, locks, timeout, *args, **kwargs): ...@@ -256,10 +258,13 @@ def RunWithLocks(fn, locks, timeout, *args, **kwargs):
qa_thread.join() qa_thread.join()
if test_blocked: blocking_lock_names = ", ".join(map(lock_name_map.get, blocking_owned_locks))
blocking_lock_names = map(lock_name_map.get, blocking_owned_locks) if not block and test_blocked:
raise qa_error.Error("QA test succeded, but was blocked by the locks: %s" % raise qa_error.Error("QA test succeded, but was blocked by locks: %s" %
", ".join(blocking_lock_names)) blocking_lock_names)
elif block and not test_blocked:
raise qa_error.Error("QA test succeded, but was not blocked as it was "
"expected to by locks: %s" % blocking_lock_names)
else: else:
_TerminateDelayFunction(termination_socket) _TerminateDelayFunction(termination_socket)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment