From 6a2d9ec550ba9e5063ccf1dd1782b53132f3bcae Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 8 Feb 2021 22:15:18 +0000 Subject: [PATCH] tests: Fix throttling of Docker pulls fixes #809 (cherry picked from commit e67e4b83b4801c797d9e2080714e78b7b24765d0) --- .ci/ansible_install.py | 6 +++--- .ci/ci_lib.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.ci/ansible_install.py b/.ci/ansible_install.py index 1c8682db..2bfe15ba 100755 --- a/.ci/ansible_install.py +++ b/.ci/ansible_install.py @@ -15,9 +15,9 @@ batches = [ ] ] -batches.extend( - ['docker pull %s' % (ci_lib.image_for_distro(distro),), 'sleep 1'] +batches.append(ci_lib.throttle( + 'docker pull %s' % (ci_lib.image_for_distro(distro),) for distro in ci_lib.DISTROS -) +)) ci_lib.run_batches(batches) diff --git a/.ci/ci_lib.py b/.ci/ci_lib.py index 8c7716d8..307483c3 100644 --- a/.ci/ci_lib.py +++ b/.ci/ci_lib.py @@ -125,6 +125,20 @@ def combine(batch): )) +def throttle(batch, pause=1): + """ + Add pauses between commands in a batch + + >>> throttle(['echo foo', 'echo bar', 'echo baz']) + ['echo foo', 'sleep 1', 'echo bar', 'sleep 1', 'echo baz'] + """ + def _with_pause(batch, pause): + for cmd in batch: + yield cmd + yield 'sleep %i' % (pause,) + return list(_with_pause(batch, pause))[:-1] + + def run_batches(batches): """ Run shell commands grouped into batches, showing an execution trace.