@@ -67,6 +67,9 @@ async def test_watch_with_decode(self):
67
67
_preload_content = False , watch = True , resource_version = '123' )
68
68
fake_resp .release .assert_called_once_with ()
69
69
70
+ # last resource_version has to be stored in the object
71
+ self .assertEqual (watch .resource_version , '2' )
72
+
70
73
async def test_watch_k8s_empty_response (self ):
71
74
"""Stop the iterator when the response is empty.
72
75
@@ -190,6 +193,32 @@ async def test_watch_timeout(self):
190
193
call (_preload_content = False , watch = True , resource_version = '1555' )])
191
194
fake_resp .release .assert_called_once_with ()
192
195
196
+ async def test_watch_timeout_with_resource_version (self ):
197
+ fake_resp = CoroutineMock ()
198
+ fake_resp .content .readline = CoroutineMock ()
199
+ fake_resp .release = Mock ()
200
+
201
+ fake_resp .content .readline .side_effect = [asyncio .TimeoutError (),
202
+ b"" ]
203
+
204
+ fake_api = Mock ()
205
+ fake_api .get_namespaces = CoroutineMock (return_value = fake_resp )
206
+ fake_api .get_namespaces .__doc__ = ':return: V1NamespaceList'
207
+
208
+ watch = kubernetes_asyncio .watch .Watch ()
209
+ async with watch .stream (fake_api .get_namespaces , resource_version = '10' ) as stream :
210
+ async for e in stream : # noqa
211
+ pass
212
+
213
+ # all calls use the passed resource version
214
+ fake_api .get_namespaces .assert_has_calls (
215
+ [call (_preload_content = False , watch = True , resource_version = '10' ),
216
+ call (_preload_content = False , watch = True , resource_version = '10' )])
217
+
218
+ fake_resp .release .assert_called_once_with ()
219
+ self .assertEqual (watch .resource_version , '10' )
220
+
221
+
193
222
if __name__ == '__main__' :
194
223
import asynctest
195
224
asynctest .main ()
0 commit comments