Skip to content

Commit 251fb27

Browse files
bors[bot]curquiza
andauthored
Merge #168
168: Add a timeout in wait_for_dump_creation r=curquiza a=curquiza Currently, the `wait_for_dump_creation` could lead to an infinite loop. Co-authored-by: Clementine Urquizar <[email protected]>
2 parents 8d92a47 + 0e941e0 commit 251fb27

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

meilisearch/tests/__init__.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import time
1+
from datetime import datetime
2+
from time import sleep
23

34
MASTER_KEY = 'masterKey'
45
BASE_URL = 'http://127.0.0.1:7700'
@@ -8,8 +9,17 @@ def clear_all_indexes(client):
89
for index in indexes:
910
client.get_index(index['uid']).delete()
1011

11-
def wait_for_dump_creation(client, dump_uid):
12-
dump_status = client.get_dump_status(dump_uid)
13-
while dump_status['status'] == 'in_progress':
14-
time.sleep(0.1)
15-
dump_status = client.get_dump_status(dump_uid)
12+
13+
# Waits until the end of the dump creation.
14+
# Raises a TimeoutError if the `timeout_in_ms` is reached.
15+
def wait_for_dump_creation(client, dump_uid, timeout_in_ms=10000, interval_in_ms=500):
16+
start_time = datetime.now()
17+
elapsed_time = 0
18+
while elapsed_time < timeout_in_ms:
19+
dump = client.get_dump_status(dump_uid)
20+
if dump['status'] != 'in_progress':
21+
return
22+
sleep(interval_in_ms / 1000)
23+
time_delta = datetime.now() - start_time
24+
elapsed_time = time_delta.seconds * 1000 + time_delta.microseconds / 1000
25+
raise TimeoutError

0 commit comments

Comments
 (0)