Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit f7d0cb0

Browse files
authored
Merge pull request #486 from cloudant/464-replication-follow-failure
Correct replicator states
2 parents 943ad11 + 1d634d6 commit f7d0cb0

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# UNRELEASED
22
- [REMOVED] Removed Python 2 compatibility from the supported environments.
33
- [FIXED] Fixed the documentation for `bookmarks`.
4+
- [FIXED] Also exit `follow_replication` for `failed` state.
45

56
# 2.14.0 (2020-08-17)
67

src/cloudant/replicator.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,12 @@ def update_state():
193193
repl_doc, state = update_state()
194194
if repl_doc:
195195
yield repl_doc
196-
if state is not None and state in ['error', 'completed']:
196+
# This is a little awkward, since 2.1 the terminal states are
197+
# "failed" and "completed", so those should be the exit states, but
198+
# for backwards compatibility with older versions "error" is also
199+
# needed. The code has always exited for "error" state even long
200+
# after 2.1 was available so that behaviour is retained.
201+
if state is not None and state in ['error', 'failed', 'completed']:
197202
return
198203

199204
# Now listen on changes feed for the state
@@ -202,7 +207,8 @@ def update_state():
202207
repl_doc, state = update_state()
203208
if repl_doc is not None:
204209
yield repl_doc
205-
if state is not None and state in ['error', 'completed']:
210+
# See note about these states
211+
if state is not None and state in ['error', 'failed', 'completed']:
206212
return
207213

208214
def stop_replication(self, repl_id):

tests/unit/replicator_tests.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,14 @@ def test_retrieve_replication_state(self):
322322
)
323323
self.replication_ids.append(repl_id)
324324
repl_state = None
325-
valid_states = ['completed', 'error', 'triggered', 'running', None]
325+
# note triggered is for versions prior to 2.1
326+
valid_states = ['completed', 'error', 'initializing', 'triggered', 'pending', 'running', 'failed', 'crashing', None]
326327
finished = False
328+
# Wait for 5 minutes or a terminal replication state
327329
for _ in range(300):
328330
repl_state = self.replicator.replication_state(repl_id)
329331
self.assertTrue(repl_state in valid_states)
330-
if repl_state in ('error', 'completed'):
332+
if repl_state in ('error', 'failed', 'completed'):
331333
finished = True
332334
break
333335
time.sleep(1)
@@ -407,7 +409,8 @@ def test_follow_replication(self):
407409
repl_id
408410
)
409411
self.replication_ids.append(repl_id)
410-
valid_states = ('completed', 'error', 'triggered', 'running', None)
412+
# note triggered is for versions prior to 2.1
413+
valid_states = ['completed', 'error', 'initializing', 'triggered', 'pending', 'running', 'failed', 'crashing', None]
411414
repl_states = []
412415
if 'scheduler' in self.client.features():
413416
state_key = 'state'

0 commit comments

Comments
 (0)