From dba2676fa7624ecc60102cf6799cac7b0447df25 Mon Sep 17 00:00:00 2001 From: toto Date: Tue, 7 Apr 2026 16:45:14 +0200 Subject: [PATCH] fix: correct singleton test for ja4_common ClickHouseClient MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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> --- .../python/ja4_common/tests/test_clickhouse.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/shared/python/ja4_common/tests/test_clickhouse.py b/shared/python/ja4_common/tests/test_clickhouse.py index c0d95ae..7f65310 100644 --- a/shared/python/ja4_common/tests/test_clickhouse.py +++ b/shared/python/ja4_common/tests/test_clickhouse.py @@ -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():