Skip to content

Commit e51caba

Browse files
committed
Test dagster-elasticsearch against Elasticsearch 9
1 parent d00af8d commit e51caba

3 files changed

Lines changed: 61 additions & 11 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

libraries/dagster-elasticsearch/pyproject.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ readme = "README.md"
55
requires-python = ">=3.10"
66
dependencies = [
77
"dagster>=1.13.0",
8-
# CI runs against an Elasticsearch 8 server; elasticsearch-py refuses
9-
# cross-major clients (e.g. v9 client + v8 server).
10-
"elasticsearch>=8.10,<9",
8+
# Loose pin: Elasticsearch 8, 9, and 10 use the same bulk + alias APIs
9+
# we exercise. Pin a specific major in your own project to match your
10+
# server. elasticsearch-py refuses cross-major (e.g. v9 client + v8
11+
# server).
12+
"elasticsearch>=8.10,<11",
1113
]
1214
dynamic = ["version"]
1315

libraries/dagster-elasticsearch/uv.lock

Lines changed: 33 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)