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

Commit 57c67f4

Browse files
authored
Merge pull request #258 from cloudant/256-fix-intermittent-test-list-replications
Fix unreliable unit tests
2 parents d05e6b9 + 4c45a59 commit 57c67f4

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

tests/unit/client_tests.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,21 @@ def test_keys(self):
264264
"""
265265
Test retrieving the list of database names
266266
"""
267+
dbs = []
267268
try:
268269
self.client.connect()
269270
self.assertEqual(list(self.client.keys()), [])
270-
self.assertEqual(
271-
self.client.keys(remote=True),
272-
self.client.all_dbs()
273-
)
271+
272+
# create 10 new test dbs
273+
for _ in range(10):
274+
dbs.append(self.client.create_database(self.dbname()).database_name)
275+
276+
self.assertTrue(set(dbs).issubset(set(self.client.keys(remote=True))))
277+
self.assertTrue(set(dbs).issubset(set(self.client.all_dbs())))
278+
274279
finally:
280+
for db in dbs:
281+
self.client.delete_database(db) # remove test db
275282
self.client.disconnect()
276283

277284
def test_get_non_existing_db_via_getitem(self):

tests/unit/replicator_tests.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,22 @@ def tearDown(self):
6161
self.target_db.delete()
6262
del self.test_target_dbname
6363
del self.target_db
64-
while self.replication_ids:
65-
self.replicator.stop_replication(self.replication_ids.pop())
64+
65+
for rep_id in self.replication_ids:
66+
max_retry = 5
67+
while True:
68+
try:
69+
self.replicator.stop_replication(rep_id)
70+
break
71+
72+
except requests.HTTPError as ex:
73+
# Retry failed attempt to delete replication document. It's
74+
# likely in an error state and receiving constant updates
75+
# via the replicator.
76+
max_retry -= 1
77+
if ex.response.status_code != 409 or max_retry == 0:
78+
raise
79+
6680
del self.replicator
6781
self.db_tear_down()
6882
super(ReplicatorTests, self).tearDown()

0 commit comments

Comments
 (0)