Skip to content

Commit b06e437

Browse files
committed
Avoid demux test flakiness
Signed-off-by: Joffrey F <[email protected]>
1 parent 0287cd9 commit b06e437

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

tests/integration/api_exec_test.py

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
from docker.utils.proxy import ProxyConfig
12
from docker.utils.socket import next_frame_header
23
from docker.utils.socket import read_exactly
3-
from docker.utils.proxy import ProxyConfig
44

5-
from .base import BaseAPIIntegrationTest, BUSYBOX
5+
from .base import BUSYBOX, BaseAPIIntegrationTest
66
from ..helpers import (
7-
requires_api_version, ctrl_with, assert_cat_socket_detached_with_keys
7+
assert_cat_socket_detached_with_keys, ctrl_with, requires_api_version,
88
)
99

1010

@@ -125,25 +125,22 @@ def test_exec_command_demux(self):
125125
script = ' ; '.join([
126126
# Write something on stdout
127127
'echo hello out',
128-
# Busybox's sleep does not handle sub-second times.
129-
# This loops takes ~0.3 second to execute on my machine.
130-
'for i in $(seq 1 50000); do echo $i>/dev/null; done',
131128
# Write something on stderr
132129
'echo hello err >&2'])
133130
cmd = 'sh -c "{}"'.format(script)
134131

135132
# tty=False, stream=False, demux=False
136133
res = self.client.exec_create(id, cmd)
137134
exec_log = self.client.exec_start(res)
138-
assert exec_log == b'hello out\nhello err\n'
135+
assert 'hello out\n' in exec_log
136+
assert 'hello err\n' in exec_log
139137

140138
# tty=False, stream=True, demux=False
141139
res = self.client.exec_create(id, cmd)
142-
exec_log = self.client.exec_start(res, stream=True)
143-
assert next(exec_log) == b'hello out\n'
144-
assert next(exec_log) == b'hello err\n'
145-
with self.assertRaises(StopIteration):
146-
next(exec_log)
140+
exec_log = list(self.client.exec_start(res, stream=True))
141+
assert len(exec_log) == 2
142+
assert 'hello out\n' in exec_log
143+
assert 'hello err\n' in exec_log
147144

148145
# tty=False, stream=False, demux=True
149146
res = self.client.exec_create(id, cmd)
@@ -152,11 +149,10 @@ def test_exec_command_demux(self):
152149

153150
# tty=False, stream=True, demux=True
154151
res = self.client.exec_create(id, cmd)
155-
exec_log = self.client.exec_start(res, demux=True, stream=True)
156-
assert next(exec_log) == (b'hello out\n', None)
157-
assert next(exec_log) == (None, b'hello err\n')
158-
with self.assertRaises(StopIteration):
159-
next(exec_log)
152+
exec_log = list(self.client.exec_start(res, demux=True, stream=True))
153+
assert len(exec_log) == 2
154+
assert (b'hello out\n', None) in exec_log
155+
assert (None, b'hello err\n') in exec_log
160156

161157
# tty=True, stream=False, demux=False
162158
res = self.client.exec_create(id, cmd, tty=True)
@@ -165,11 +161,10 @@ def test_exec_command_demux(self):
165161

166162
# tty=True, stream=True, demux=False
167163
res = self.client.exec_create(id, cmd, tty=True)
168-
exec_log = self.client.exec_start(res, stream=True)
169-
assert next(exec_log) == b'hello out\r\n'
170-
assert next(exec_log) == b'hello err\r\n'
171-
with self.assertRaises(StopIteration):
172-
next(exec_log)
164+
exec_log = list(self.client.exec_start(res, stream=True))
165+
assert len(exec_log) == 2
166+
assert 'hello out\r\n' in exec_log
167+
assert 'hello err\r\n' in exec_log
173168

174169
# tty=True, stream=False, demux=True
175170
res = self.client.exec_create(id, cmd, tty=True)
@@ -178,11 +173,10 @@ def test_exec_command_demux(self):
178173

179174
# tty=True, stream=True, demux=True
180175
res = self.client.exec_create(id, cmd, tty=True)
181-
exec_log = self.client.exec_start(res, demux=True, stream=True)
182-
assert next(exec_log) == (b'hello out\r\n', None)
183-
assert next(exec_log) == (b'hello err\r\n', None)
184-
with self.assertRaises(StopIteration):
185-
next(exec_log)
176+
exec_log = list(self.client.exec_start(res, demux=True, stream=True))
177+
assert len(exec_log) == 2
178+
assert (b'hello out\r\n', None) in exec_log
179+
assert (b'hello err\r\n', None) in exec_log
186180

187181
def test_exec_start_socket(self):
188182
container = self.client.create_container(BUSYBOX, 'cat',

0 commit comments

Comments
 (0)