Skip to content

Commit c656764

Browse files
committed
fix: reset _stop when new stream is called
1 parent 168c5e7 commit c656764

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

watch/watch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def stream(self, func, *args, **kwargs):
109109
watch.stop()
110110
"""
111111

112+
self._stop = False
112113
return_type = self.get_return_type(func)
113114
kwargs['watch'] = True
114115
kwargs['_preload_content'] = False

watch/watch_test.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,33 @@ def test_watch_with_decode(self):
5858
fake_resp.close.assert_called_once()
5959
fake_resp.release_conn.assert_called_once()
6060

61+
def test_watch_stream_twice(self):
62+
w = Watch(float)
63+
for step in ['first', 'second']:
64+
fake_resp = Mock()
65+
fake_resp.close = Mock()
66+
fake_resp.release_conn = Mock()
67+
fake_resp.read_chunked = Mock(
68+
return_value=['{"type": "ADDED", "object": 1}\n'] * 4)
69+
70+
fake_api = Mock()
71+
fake_api.get_namespaces = Mock(return_value=fake_resp)
72+
fake_api.get_namespaces.__doc__ = ':return: V1NamespaceList'
73+
74+
count = 1
75+
for e in w.stream(fake_api.get_namespaces):
76+
count += 1
77+
if count == 3:
78+
w.stop()
79+
80+
self.assertEqual(count, 3)
81+
fake_api.get_namespaces.assert_called_once_with(
82+
_preload_content=False, watch=True)
83+
fake_resp.read_chunked.assert_called_once_with(
84+
decode_content=False)
85+
fake_resp.close.assert_called_once()
86+
fake_resp.release_conn.assert_called_once()
87+
6188
def test_unmarshal_with_float_object(self):
6289
w = Watch()
6390
event = w.unmarshal_event('{"type": "ADDED", "object": 1}', 'float')

0 commit comments

Comments
 (0)