From e29e3f8da4b5f0e2f9a32206abd7efd2f1333928 Mon Sep 17 00:00:00 2001 From: Evan Shaw Date: Sat, 25 Feb 2017 13:14:32 +1300 Subject: [PATCH] Test for parallel_execute with limit Signed-off-by: Evan Shaw --- tests/unit/parallel_test.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/unit/parallel_test.py b/tests/unit/parallel_test.py index 6b8045f14..d10948eb0 100644 --- a/tests/unit/parallel_test.py +++ b/tests/unit/parallel_test.py @@ -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 = []