1
+ from docker .utils .proxy import ProxyConfig
1
2
from docker .utils .socket import next_frame_header
2
3
from docker .utils .socket import read_exactly
3
- from docker .utils .proxy import ProxyConfig
4
4
5
- from .base import BaseAPIIntegrationTest , BUSYBOX
5
+ from .base import BUSYBOX , BaseAPIIntegrationTest
6
6
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 ,
8
8
)
9
9
10
10
@@ -125,25 +125,22 @@ def test_exec_command_demux(self):
125
125
script = ' ; ' .join ([
126
126
# Write something on stdout
127
127
'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' ,
131
128
# Write something on stderr
132
129
'echo hello err >&2' ])
133
130
cmd = 'sh -c "{}"' .format (script )
134
131
135
132
# tty=False, stream=False, demux=False
136
133
res = self .client .exec_create (id , cmd )
137
134
exec_log = self .client .exec_start (res )
138
- assert exec_log == b'hello out\n hello err\n '
135
+ assert 'hello out\n ' in exec_log
136
+ assert 'hello err\n ' in exec_log
139
137
140
138
# tty=False, stream=True, demux=False
141
139
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
147
144
148
145
# tty=False, stream=False, demux=True
149
146
res = self .client .exec_create (id , cmd )
@@ -152,11 +149,10 @@ def test_exec_command_demux(self):
152
149
153
150
# tty=False, stream=True, demux=True
154
151
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
160
156
161
157
# tty=True, stream=False, demux=False
162
158
res = self .client .exec_create (id , cmd , tty = True )
@@ -165,11 +161,10 @@ def test_exec_command_demux(self):
165
161
166
162
# tty=True, stream=True, demux=False
167
163
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
173
168
174
169
# tty=True, stream=False, demux=True
175
170
res = self .client .exec_create (id , cmd , tty = True )
@@ -178,11 +173,10 @@ def test_exec_command_demux(self):
178
173
179
174
# tty=True, stream=True, demux=True
180
175
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
186
180
187
181
def test_exec_start_socket (self ):
188
182
container = self .client .create_container (BUSYBOX , 'cat' ,
0 commit comments