|
|
@@ -1,6 +1,8 @@
|
|
|
from __future__ import absolute_import
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
+from threading import Lock
|
|
|
+
|
|
|
import six
|
|
|
from docker.errors import APIError
|
|
|
|
|
|
@@ -40,6 +42,30 @@ def test_parallel_execute():
|
|
|
assert errors == {}
|
|
|
|
|
|
|
|
|
+def test_parallel_execute_with_limit():
|
|
|
+ limit = 1
|
|
|
+ tasks = 20
|
|
|
+ lock = Lock()
|
|
|
+
|
|
|
+ def f(obj):
|
|
|
+ locked = lock.acquire(False)
|
|
|
+ # we should always get the lock because we're the only thread running
|
|
|
+ assert locked
|
|
|
+ lock.release()
|
|
|
+ return None
|
|
|
+
|
|
|
+ results, errors = parallel_execute(
|
|
|
+ objects=list(range(tasks)),
|
|
|
+ func=f,
|
|
|
+ get_name=six.text_type,
|
|
|
+ msg="Testing",
|
|
|
+ limit=limit,
|
|
|
+ )
|
|
|
+
|
|
|
+ assert results == tasks*[None]
|
|
|
+ assert errors == {}
|
|
|
+
|
|
|
+
|
|
|
def test_parallel_execute_with_deps():
|
|
|
log = []
|
|
|
|