Skip to content

Commit eb89d69

Browse files
Bug fix/wait for hot backup (#389)
* workaround: give the cluster time to restore the hot backup * implement waiting for cluster resillience after hotbackup restore * Adapting the wait function * Adapting the wait function * Adapting the wait function * Adapting the wait function --------- Co-authored-by: Alex Petenchea <alex.petenchea@gmail.com>
1 parent c85aa15 commit eb89d69

1 file changed

Lines changed: 39 additions & 2 deletions

File tree

tests/test_backup.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,48 @@
1111
BackupGetError,
1212
BackupRestoreError,
1313
BackupUploadError,
14+
ReplicationClusterInventoryError,
1415
)
1516
from tests.helpers import assert_raises
1617

1718

19+
def wait_for_cluster_resilient(sys_db):
20+
collections_in_sync = False
21+
max_attempts = 100
22+
23+
while not collections_in_sync and max_attempts > 0:
24+
count_in_sync = 0
25+
count_still_waiting = 0
26+
27+
try:
28+
inventory = sys_db.replication.cluster_inventory(include_system=True)
29+
except ReplicationClusterInventoryError:
30+
print("Failed to get cluster inventory, retrying...")
31+
time.sleep(1)
32+
max_attempts -= 1
33+
continue
34+
35+
collections_in_sync = True
36+
for col in inventory["collections"]:
37+
if not col["all_in_sync"]:
38+
count_still_waiting += 1
39+
collections_in_sync = False
40+
else:
41+
count_in_sync += 1
42+
43+
if not collections_in_sync:
44+
if max_attempts % 50 == 0:
45+
print(inventory)
46+
print(f"In sync: {count_in_sync}")
47+
print(f"Still not in sync: {count_still_waiting}")
48+
time.sleep(1)
49+
50+
max_attempts -= 1
51+
52+
if not collections_in_sync:
53+
raise Exception("Collections didn't come in sync!")
54+
55+
1856
def test_backup_management(sys_db, bad_db, cluster, skip_tests, db_version):
1957
if "enterprise" in skip_tests:
2058
pytest.skip("Only for ArangoDB enterprise edition")
@@ -112,8 +150,7 @@ def test_backup_management(sys_db, bad_db, cluster, skip_tests, db_version):
112150
result = sys_db.backup.restore(backup_id_foo)
113151
assert isinstance(result, dict)
114152

115-
# Wait for restore to complete
116-
time.sleep(10)
153+
wait_for_cluster_resilient(sys_db)
117154

118155
# Test restore backup with bad database.
119156
with assert_raises(BackupRestoreError) as err:

0 commit comments

Comments
 (0)