Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions integration/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,47 @@ async def test_async_client_is_ready() -> None:
assert await client.is_ready()


def test_client_is_not_live() -> None:
assert not weaviate.WeaviateClient(
connection_params=weaviate.connect.ConnectionParams.from_url(
"http://localhost:8080", 50051
),
skip_init_checks=True,
).is_live()


def test_client_is_live() -> None:
with weaviate.connect_to_wcs(
cluster_url=WCS_URL, auth_credentials=WCS_CREDS, skip_init_checks=True
) as client:
assert client.is_live()


@pytest.mark.asyncio
async def test_async_client_is_live() -> None:
async with weaviate.use_async_with_weaviate_cloud(
cluster_url=WCS_URL, auth_credentials=WCS_CREDS, skip_init_checks=True
) as client:
assert await client.is_live()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are great but there's one more case I'd like added to cover this change when init checks are skipped and one of the ports is wrong, which looks like:

def test_client_is_not_live_with_wrong_rest_port() -> None:
    with weaviate.connect_to_local(
        port=9000, # wrong
        skip_init_checks=True
    ) as client:
        assert not client.is_live()

def test_client_is_not_live_with_wrong_grpc_port() -> None:
    with weaviate.connect_to_local(
        grpc_port=90000, # wrong
        skip_init_checks=True
    ) as client:
        assert not client.is_live()

please could you add this case for sync and async then I'll merge!

Copy link
Contributor Author

@sylvinho81 sylvinho81 Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tsmith023

By looking at your suggested tests we think that they will fail and raise the exception like in the existing tests. If we specify a wrong port the connection will fail.

def test_connect_to_wrong_wcs() -> None:
    with pytest.raises(WeaviateStartUpError):
        weaviate.connect_to_wcs("does-not-exist", auth_credentials=WCS_CREDS, skip_init_checks=True)


def test_connect_to_wrong_local() -> None:
    with pytest.raises(expected_exception=WeaviateStartUpError):
        weaviate.connect_to_local("does-not-exist", skip_init_checks=True)


def test_connect_to_wrong_custom() -> None:
    with pytest.raises(expected_exception=WeaviateStartUpError):
        weaviate.connect_to_custom(
            "does-not-exist",
            http_port=1234,
            http_secure=False,
            grpc_host="does-not-exist",
            grpc_port=2345,
            grpc_secure=False,
            skip_init_checks=True,
        )

Instead we could just create the connection with the right ports and change it in the context. Something like this:

def test_client_is_not_live_with_wrong_rest_port() -> None:
    with weaviate.connect_to_local(skip_init_checks=True) as client:
        # Simulate a wrong REST port after connecting.
        client._connection.url = "http://localhost:9000"
        assert not client.is_live()

def test_client_is_not_live_with_wrong_grpc_port() -> None:
    with weaviate.connect_to_local(skip_init_checks=True) as client:
        # Simulate a wrong gRPC port after connecting.
        client._connection._connection_params.grpc.port = 90000
        # Clear channel and stub so ping fails and cleanup doesn't break
        client._connection._grpc_channel = None
        client._connection._grpc_stub = None
        assert not client.is_live()

Just let us know if this works and we add those tests.
Thanks

Copy link
Collaborator

@tsmith023 tsmith023 Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, apologies for getting that so wrong! I do wonder whether skip_init_checks should truly skip all init checks so that it is less confusing 🤔

The second example looks good!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes have been pushed, ready for review.



def test_client_is_not_live_with_wrong_rest_port() -> None:
with weaviate.connect_to_local(skip_init_checks=True) as client:
# Simulate a wrong REST port after connecting.
client._connection.url = "http://localhost:9000"
assert not client.is_live()


def test_client_is_not_live_with_wrong_grpc_port() -> None:
with weaviate.connect_to_local(skip_init_checks=True) as client:
# Simulate a wrong gRPC port after connecting.
client._connection._connection_params.grpc.port = 90000
# Clear channel and stub so ping fails and cleanup doesn't break
client._connection._grpc_channel = None
client._connection._grpc_stub = None
assert not client.is_live()


def test_local_proxies() -> None:
with weaviate.connect_to_local(
additional_config=wvc.init.AdditionalConfig(
Expand Down
52 changes: 47 additions & 5 deletions weaviate/client_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

from typing import (
Any,
Awaitable,
Dict,
Generic,
Optional,
Tuple,
Type,
Union,
cast,
)

from httpx import Response
Expand Down Expand Up @@ -151,9 +153,14 @@ def connect(self) -> executor.Result[None]:
method=self._connection.connect,
)

def is_live(self) -> executor.Result[bool]:
def resp(res: Response) -> bool:
return res.status_code == 200
def __check_grpc_live(self) -> executor.Result[bool]:
"""Check if the gRPC endpoint is live by pinging it."""
grpc_colour: executor.Colour = (
"async" if isinstance(self._connection, ConnectionAsync) else "sync"
)

def resp(_: None) -> bool:
return True

def exc(e: Exception) -> bool:
print(e)
Expand All @@ -162,8 +169,43 @@ def exc(e: Exception) -> bool:
return executor.execute(
response_callback=resp,
exception_callback=exc,
method=self._connection.get,
path="/.well-known/live",
method=self._connection._ping_grpc,
colour=grpc_colour,
)

def is_live(self) -> executor.Result[bool]:
"""Check if the Weaviate instance is live by pinging both HTTP and gRPC endpoints.

Returns:
`True` if both HTTP and gRPC endpoints are live, `False` otherwise.
"""

def resp(res: Response) -> Union[bool, Awaitable[bool]]:
if res.status_code != 200:
return False

# HTTP is live, now check gRPC
grpc_result = self.__check_grpc_live()
if isinstance(grpc_result, Awaitable):

async def await_grpc_result() -> bool:
return await grpc_result

return cast(Awaitable[bool], await_grpc_result())
return grpc_result

def exc(e: Exception) -> bool:
print(e)
return False

return cast(
executor.Result[bool],
executor.execute(
response_callback=resp,
exception_callback=exc,
method=self._connection.get,
path="/.well-known/live",
),
)

def is_ready(self) -> executor.Result[bool]:
Expand Down
Loading