Skip to content

Commit 549e2a6

Browse files
authored
Update dagster-elasticsearch lockfile (#306)
* Update dagster-elasticsearch lockfile * Pin elasticsearch client to v8 for tests * Test dagster-elasticsearch against Elasticsearch 9
1 parent 74400ea commit 549e2a6

2 files changed

Lines changed: 387 additions & 349 deletions

File tree

libraries/dagster-elasticsearch/dagster_elasticsearch_tests/conftest.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,37 @@
11
import os
2+
import time
23
import uuid
34
from collections.abc import Generator
45

56
import pytest
67
from docker.errors import DockerException
78
from elasticsearch import Elasticsearch
9+
from elasticsearch.exceptions import ConnectionError as ESConnectionError
810
from testcontainers.core.container import DockerContainer
911
from testcontainers.core.waiting_utils import wait_for_logs
1012

1113
ES_IMAGE = os.environ.get("ES_TEST_IMAGE", "docker.elastic.co/elasticsearch/elasticsearch:9.1.3")
1214
ES_PORT = 9200
1315

1416

17+
def _wait_for_elasticsearch(url: str, timeout: float = 60.0) -> None:
18+
deadline = time.monotonic() + timeout
19+
last_error: Exception | None = None
20+
21+
while time.monotonic() < deadline:
22+
client = Elasticsearch(hosts=[url], verify_certs=False)
23+
try:
24+
client.info()
25+
return
26+
except ESConnectionError as exc:
27+
last_error = exc
28+
time.sleep(1)
29+
finally:
30+
client.close()
31+
32+
raise TimeoutError(f"Elasticsearch did not become ready at {url}") from last_error
33+
34+
1535
@pytest.fixture(scope="session")
1636
def es_url() -> Generator[str, None, None]:
1737
"""Yield a base URL for an Elasticsearch cluster.
@@ -45,7 +65,9 @@ def es_url() -> Generator[str, None, None]:
4565
wait_for_logs(container, "started")
4666
host = container.get_container_host_ip()
4767
port = container.get_exposed_port(ES_PORT)
48-
yield f"http://{host}:{port}"
68+
url = f"http://{host}:{port}"
69+
_wait_for_elasticsearch(url)
70+
yield url
4971
finally:
5072
container.stop()
5173

0 commit comments

Comments
 (0)