summaryrefslogtreecommitdiff
path: root/taskflow/tests/unit/test_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'taskflow/tests/unit/test_utils.py')
-rw-r--r--taskflow/tests/unit/test_utils.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/taskflow/tests/unit/test_utils.py b/taskflow/tests/unit/test_utils.py
index 4518f96..5d4b761 100644
--- a/taskflow/tests/unit/test_utils.py
+++ b/taskflow/tests/unit/test_utils.py
@@ -17,7 +17,10 @@
import collections
import functools
import inspect
+import random
import sys
+import threading
+import time
import six
import testtools
@@ -437,6 +440,36 @@ class CachedPropertyTest(test.TestCase):
self.assertEqual(None, inspect.getdoc(A.b))
+ def test_threaded_access_property(self):
+ called = collections.deque()
+
+ class A(object):
+ @misc.cachedproperty
+ def b(self):
+ called.append(1)
+ # NOTE(harlowja): wait for a little and give some time for
+ # another thread to potentially also get in this method to
+ # also create the same property...
+ time.sleep(random.random() * 0.5)
+ return 'b'
+
+ a = A()
+ threads = []
+ try:
+ for _i in range(0, 20):
+ t = threading.Thread(target=lambda: a.b)
+ t.daemon = True
+ threads.append(t)
+ for t in threads:
+ t.start()
+ finally:
+ while threads:
+ t = threads.pop()
+ t.join()
+
+ self.assertEqual(1, len(called))
+ self.assertEqual('b', a.b)
+
class AttrDictTest(test.TestCase):
def test_ok_create(self):