From 2b875590cf89cbfa519c7eb343eb2862f5fd8226 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Wed, 5 Mar 2014 18:49:41 -0800 Subject: [PATCH] Add a delay before releasing the lock To avoid when the lock gets released and the time to acquire is below the float tolerance add-on a sleep to ensure that there is always some variation in timing before the acquisition by another thread. If the cause of this bug is a time shift (ntpd?) then this will not be a fix (a fix for that is only available in py3.3). Fixes bug 1288521 Change-Id: I3294e81ce043a2c91730bb614020bb79c867dcdb --- taskflow/tests/unit/test_utils_lock_utils.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/taskflow/tests/unit/test_utils_lock_utils.py b/taskflow/tests/unit/test_utils_lock_utils.py index 7749eb93..475ee059 100644 --- a/taskflow/tests/unit/test_utils_lock_utils.py +++ b/taskflow/tests/unit/test_utils_lock_utils.py @@ -23,6 +23,11 @@ from concurrent import futures from taskflow import test from taskflow.utils import lock_utils +# NOTE(harlowja): Sleep a little so time.time() can not be the same (which will +# cause false positives when our overlap detection code runs). If there are +# real overlaps then they will still exist. +NAPPY_TIME = 0.05 + def _find_overlaps(times, start, end): overlaps = 0 @@ -39,10 +44,12 @@ def _spawn_variation(readers, writers, max_workers=None): def read_func(): with lock.read_lock(): start_stops.append(('r', time.time(), time.time())) + time.sleep(NAPPY_TIME) def write_func(): with lock.write_lock(): start_stops.append(('w', time.time(), time.time())) + time.sleep(NAPPY_TIME) if max_workers is None: max_workers = max(0, readers) + max(0, writers)