@@ -170,7 +170,11 @@ def test_portforward_raw(self):
170
170
name = 'portforward-raw-' + short_uuid ()
171
171
pod_manifest = manifest_with_command (
172
172
name ,
173
- 'for port in 1234 1235;do ((while true;do nc -l -p $port -e /bin/cat; done)&);done;sleep 60' ,
173
+ ' ' .join ((
174
+ '((while true;do nc -l -p 1234 -e /bin/cat; done)&);' ,
175
+ '((while true;do nc -l -p 1235 -e /bin/cat; done)&);' ,
176
+ 'sleep 60' ,
177
+ ))
174
178
)
175
179
resp = api .create_namespaced_pod (body = pod_manifest ,
176
180
namespace = 'default' )
@@ -188,7 +192,8 @@ def test_portforward_raw(self):
188
192
189
193
pf = portforward (api .connect_get_namespaced_pod_portforward ,
190
194
name , 'default' ,
191
- ports = '1234,1235' )
195
+ ports = '1234,1235,1236' )
196
+ self .assertTrue (pf .connected )
192
197
sock1234 = pf .socket (1234 )
193
198
sock1235 = pf .socket (1235 )
194
199
sock1234 .setblocking (True )
@@ -212,19 +217,23 @@ def test_portforward_raw(self):
212
217
break
213
218
if sock1234 in r :
214
219
data = sock1234 .recv (1024 )
215
- if data :
216
- reply1234 += data
217
- else :
218
- assert False , 'Unexpected sock1234 close'
220
+ self .assertNotEqual (data , b'' , "Unexpected socket close" )
221
+ reply1234 += data
219
222
if sock1235 in r :
220
223
data = sock1235 .recv (1024 )
221
- if data :
222
- reply1235 += data
223
- else :
224
- assert False , 'Unexpected sock1235 close'
224
+ self .assertNotEqual (data , b'' , "Unexpected socket close" )
225
+ reply1235 += data
225
226
self .assertEqual (reply1234 , sent1234 )
226
227
self .assertEqual (reply1235 , sent1235 )
228
+ self .assertTrue (pf .connected )
229
+
230
+ sock = pf .socket (1236 )
231
+ self .assertRaises (BrokenPipeError , sock .sendall , b'This should fail...' )
232
+ self .assertIsNotNone (pf .error (1236 ))
233
+ sock .close ()
234
+
227
235
for sock in (sock1234 , sock1235 ):
236
+ self .assertTrue (pf .connected )
228
237
sent = b'Another test using fileno %s' % str (sock .fileno ()).encode ()
229
238
sock .sendall (sent )
230
239
reply = b''
@@ -233,12 +242,11 @@ def test_portforward_raw(self):
233
242
if not r :
234
243
break
235
244
data = sock .recv (1024 )
236
- if data :
237
- reply += data
238
- else :
239
- assert False , 'Unexpected sock close'
245
+ self .assertNotEqual (data , b'' , "Unexpected socket close" )
246
+ reply += data
240
247
self .assertEqual (reply , sent )
241
248
sock .close ()
249
+ self .assertFalse (pf .connected )
242
250
self .assertIsNone (pf .error (1234 ))
243
251
self .assertIsNone (pf .error (1235 ))
244
252
0 commit comments