fix: correct singleton test for ja4_common ClickHouseClient
get_client() returns a lazy ClickHouseClient wrapper — clickhouse_connect.get_client is only called on .connect(), not at construction time. Remove incorrect assertion that expected call_count==1 at module-level get_client() call. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@ -26,17 +26,15 @@ def test_client_reconnects_on_ping_fail():
|
||||
|
||||
|
||||
def test_get_client_returns_same_instance_on_second_call():
|
||||
"""get_client() is a singleton: returns the same object on repeated calls."""
|
||||
"""get_client() is a singleton: returns the same ClickHouseClient wrapper on repeated calls.
|
||||
Note: clickhouse_connect.get_client is only called lazily on .connect(), not on get_client().
|
||||
"""
|
||||
ch_module._client = None
|
||||
c1 = get_client()
|
||||
c2 = get_client()
|
||||
assert c1 is c2
|
||||
# Reset for other tests
|
||||
ch_module._client = None
|
||||
with patch("ja4_common.clickhouse.clickhouse_connect.get_client") as mock_gc:
|
||||
mock_inner = MagicMock()
|
||||
mock_inner.ping.return_value = True
|
||||
mock_gc.return_value = mock_inner
|
||||
c1 = get_client()
|
||||
c2 = get_client()
|
||||
assert c1 is c2
|
||||
# connect() should have been called once for c1; c2 reuses the same instance
|
||||
assert mock_gc.call_count == 1
|
||||
|
||||
|
||||
def test_client_query_delegates_to_inner():
|
||||
|
||||
Reference in New Issue
Block a user