File tree Expand file tree Collapse file tree 2 files changed +12
-12
lines changed Expand file tree Collapse file tree 2 files changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -174,16 +174,20 @@ async def next(self):
174
174
175
175
line = line .decode ('utf8' )
176
176
177
+ # Special case for faster log streaming
178
+ if self .return_type == 'str' :
179
+ if line == '' :
180
+ # end of log
181
+ raise StopAsyncIteration
182
+ return line
183
+
177
184
# Stop the iterator if K8s sends an empty response. This happens when
178
185
# eg the supplied timeout has expired.
179
186
if line == '' :
180
187
if watch_forever :
181
188
self ._reconnect ()
182
189
continue
183
-
184
- # Special case for faster log streaming
185
- if self .return_type == 'str' :
186
- return line
190
+ raise StopAsyncIteration
187
191
188
192
# retry 410 error only once
189
193
try :
Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ async def test_watch_for_follow(self):
74
74
fake_resp = AsyncMock ()
75
75
fake_resp .content .readline = AsyncMock ()
76
76
fake_resp .release = Mock ()
77
- side_effects = ['log_line_1' , 'log_line_2' ]
77
+ side_effects = ['log_line_1' , 'log_line_2' , '' ]
78
78
side_effects = [_ .encode ('utf8' ) for _ in side_effects ]
79
79
side_effects .extend ([AssertionError ('Should not have been called' )])
80
80
fake_resp .content .readline .side_effect = side_effects
@@ -84,16 +84,12 @@ async def test_watch_for_follow(self):
84
84
fake_api .read_namespaced_pod_log .__doc__ = ':param follow:\n :type follow: bool\n :rtype: str'
85
85
86
86
watch = kubernetes_asyncio .watch .Watch ()
87
- count = 1
87
+ logs = []
88
88
async with watch :
89
89
async for e in watch .stream (fake_api .read_namespaced_pod_log ):
90
- self .assertEqual ("log_line_1" , e )
91
- # Stop the watch. This must not return the next event which would
92
- # be an AssertionError exception.
93
- count += 1
94
- if count == len (side_effects ) - 1 :
95
- watch .stop ()
90
+ logs .append (e )
96
91
92
+ self .assertListEqual (logs , ['log_line_1' , 'log_line_2' ])
97
93
fake_api .read_namespaced_pod_log .assert_called_once_with (
98
94
_preload_content = False , follow = True )
99
95
fake_resp .release .assert_called_once_with ()
You can’t perform that action at this time.
0 commit comments