Skip to content

Commit 6a2d9ec

Browse files
committed
tests: Fix throttling of Docker pulls
fixes #809 (cherry picked from commit e67e4b8)
1 parent 9d404e0 commit 6a2d9ec

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

.ci/ansible_install.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
]
1616
]
1717

18-
batches.extend(
19-
['docker pull %s' % (ci_lib.image_for_distro(distro),), 'sleep 1']
18+
batches.append(ci_lib.throttle(
19+
'docker pull %s' % (ci_lib.image_for_distro(distro),)
2020
for distro in ci_lib.DISTROS
21-
)
21+
))
2222

2323
ci_lib.run_batches(batches)

.ci/ci_lib.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,20 @@ def combine(batch):
125125
))
126126

127127

128+
def throttle(batch, pause=1):
129+
"""
130+
Add pauses between commands in a batch
131+
132+
>>> throttle(['echo foo', 'echo bar', 'echo baz'])
133+
['echo foo', 'sleep 1', 'echo bar', 'sleep 1', 'echo baz']
134+
"""
135+
def _with_pause(batch, pause):
136+
for cmd in batch:
137+
yield cmd
138+
yield 'sleep %i' % (pause,)
139+
return list(_with_pause(batch, pause))[:-1]
140+
141+
128142
def run_batches(batches):
129143
""" Run shell commands grouped into batches, showing an execution trace.
130144

0 commit comments

Comments
 (0)