Skip to content

Commit 8c95554

Browse files
alexanderankintotallyzen
authored and
bstrausser
committed
fix(clickhouse): clickhouse waiting (testcontainers#428)
im not actually sure if this fixes it but does: make clickhouse waiting look more like java-tc many other discussions about removing dependency on sqlalchemy + drivers --------- Co-authored-by: Bálint Bartha <[email protected]>
1 parent 2f75b21 commit 8c95554

File tree

1 file changed

+9
-7
lines changed
  • modules/clickhouse/testcontainers/clickhouse

1 file changed

+9
-7
lines changed

modules/clickhouse/testcontainers/clickhouse/__init__.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
# under the License.
1313
import os
1414
from typing import Optional
15-
16-
import clickhouse_driver
17-
from clickhouse_driver.errors import Error
15+
from urllib.error import HTTPError, URLError
16+
from urllib.request import urlopen
1817

1918
from testcontainers.core.generic import DbContainer
2019
from testcontainers.core.utils import raise_for_deprecated_parameter
@@ -48,7 +47,7 @@ def __init__(
4847
username: Optional[str] = None,
4948
password: Optional[str] = None,
5049
dbname: Optional[str] = None,
51-
**kwargs
50+
**kwargs,
5251
) -> None:
5352
raise_for_deprecated_parameter(kwargs, "user", "username")
5453
super().__init__(image=image, **kwargs)
@@ -57,11 +56,14 @@ def __init__(
5756
self.dbname = dbname or os.environ.get("CLICKHOUSE_DB", "test")
5857
self.port = port
5958
self.with_exposed_ports(self.port)
59+
self.with_exposed_ports(8123)
6060

61-
@wait_container_is_ready(Error, EOFError)
61+
@wait_container_is_ready(HTTPError, URLError)
6262
def _connect(self) -> None:
63-
with clickhouse_driver.Client.from_url(self.get_connection_url()) as client:
64-
client.execute("SELECT version()")
63+
# noinspection HttpUrlsUsage
64+
url = f"http://{self.get_container_host_ip()}:{self.get_exposed_port(8123)}"
65+
with urlopen(url) as r:
66+
assert b"Ok" in r.read()
6567

6668
def _configure(self) -> None:
6769
self.with_env("CLICKHOUSE_USER", self.username)

0 commit comments

Comments
 (0)