Skip to content

Commit

Permalink
Merge pull request #47 from sanders41/wait
Browse files Browse the repository at this point in the history
Wait for Meilisearch to start
  • Loading branch information
sanders41 authored Dec 7, 2023
2 parents d7c9ce0 + d19b0c3 commit fa0a369
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pytest_meilisearch/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pytest
from meilisearch_python_sdk import AsyncClient, Client
from meilisearch_python_sdk.errors import MeilisearchError

from pytest_meilisearch._internal import determine_clear_indexes, determine_client_scope
from pytest_meilisearch._meilisearch_server import MeilisearchServer
Expand Down Expand Up @@ -131,14 +132,26 @@ def meilisearch_url(pytestconfig):
@pytest.fixture(scope="session", autouse=True)
def start_meilisearch(pytestconfig):
if pytestconfig.getvalue("start_meilisearch"):
meilisearch_url = _create_meilisarch_url(pytestconfig)
server = MeilisearchServer(
url=_create_meilisarch_url(pytestconfig),
url=meilisearch_url,
port=pytestconfig.getvalue("meilisearch_port"),
meilisearch_version=pytestconfig.getvalue("meilisearch_version"),
start_timeout=pytestconfig.getvalue("meilisearch_start_timeout"),
api_key=pytestconfig.getvalue("meilisearch_master_key"),
)
server.start()
client = Client(meilisearch_url, pytestconfig.getvalue("meilisearch_master_key"))
tries = 10
for i in range(tries):
try:
health = client.health()
if health.status == "available":
break
except MeilisearchError:
pass
if i == tries - 1:
pytest.fail("Unable to start the Meilisearch server")
yield
if pytestconfig.getvalue("start_meilisearch"):
server.stop()
Expand Down

0 comments on commit fa0a369

Please sign in to comment.