Skip to content

Commit

Permalink
fix: Get container host addresses from testcontainers (#3946)
Browse files Browse the repository at this point in the history
* fix: get container host addresses from testcontainers

Signed-off-by: tokoko <[email protected]>

* resolve trino container host with testcontainers

Signed-off-by: tokoko <[email protected]>

---------

Signed-off-by: tokoko <[email protected]>
  • Loading branch information
tokoko authored Mar 5, 2024
1 parent 5e0af8f commit 2cf1a0f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ def __init__(
"must be include into pytest plugins"
)
self.exposed_port = self.container.get_exposed_port("8080")
self.container_host = self.container.get_container_host_ip()
self.client = Trino(
user="user",
catalog="memory",
host="localhost",
host=self.container_host,
port=self.exposed_port,
source="trino-python-client",
http_scheme="http",
Expand Down Expand Up @@ -123,7 +124,7 @@ def get_prefixed_table_name(self, suffix: str) -> str:

def create_offline_store_config(self) -> FeastConfigBaseModel:
return TrinoOfflineStoreConfig(
host="localhost",
host=self.container_host,
port=self.exposed_port,
catalog="memory",
dataset=self.project_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def create_online_store(self) -> Dict[str, str]:
container=self.container, predicate=log_string_to_wait_for, timeout=10
)
exposed_port = self.container.get_exposed_port("6379")
return {"type": "redis", "connection_string": f"localhost:{exposed_port},db=0"}
container_host = self.container.get_container_host_ip()
return {
"type": "redis",
"connection_string": f"{container_host}:{exposed_port},db=0",
}

def teardown(self):
self.container.stop()
6 changes: 4 additions & 2 deletions sdk/python/tests/unit/test_sql_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ def pg_registry():
)
logger.info("Waited for %s seconds until postgres container was up", waited)
container_port = container.get_exposed_port(5432)
container_host = container.get_container_host_ip()

registry_config = RegistryConfig(
registry_type="sql",
path=f"postgresql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@127.0.0.1:{container_port}/{POSTGRES_DB}",
path=f"postgresql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{container_host}:{container_port}/{POSTGRES_DB}",
)

yield SqlRegistry(registry_config, "project", None)
Expand Down Expand Up @@ -100,10 +101,11 @@ def mysql_registry():
)
logger.info("Waited for %s seconds until mysql container was up", waited)
container_port = container.get_exposed_port(3306)
container_host = container.get_container_host_ip()

registry_config = RegistryConfig(
registry_type="sql",
path=f"mysql+pymysql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@127.0.0.1:{container_port}/{POSTGRES_DB}",
path=f"mysql+pymysql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{container_host}:{container_port}/{POSTGRES_DB}",
)

yield SqlRegistry(registry_config, "project", None)
Expand Down

0 comments on commit 2cf1a0f

Please sign in to comment.